w3resource logo

:

Python Exercises

Python: Create a random vector of size 10 and sort it

Python NumPy: Random Exercise-8 with Solution

Write a Python program to create a random vector of size 10 and sort it.

Sample Solution :-

Python Code :

import numpy as np
x = np.random.random(10)
print("Original array:")
print(x)
x.sort()
print("Sorted array:")
print(x)

Sample Output:

Original array:                                                        
[ 0.73123073  0.67714015  0.95615347  0.4759837   0.88789818  0.69104042                                                                      
  0.59996415  0.26144489  0.51618644  0.89943882]                      
Sorted array:                                                          
[ 0.26144489  0.4759837   0.51618644  0.59996415  0.67714015  0.69104042                                                                      
  0.73123073  0.88789818  0.89943882  0.95615347] 

Python Code Editor:

Improve this sample solution and post your code through Disqus