Sorting a Random Vector

Write a NumPy program to create a random vector of size 10 and sort it. Return the sorted vector.

Example 1:

No specific inputs. 
Outputs will be random due to random vector generation.

Example 2:

No specific inputs. 
Outputs will be random due to random vector generation.

You can use np.random.rand() function to generate a random vector and np.sort() function to sort it.

import numpy as np

def sort_vector():
    vector = np.random.rand(10)
    return np.sort(vector)

print(sort_vector())
print(sort_vector())

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!