w3resource
NumPy Exercises

NumPy: Create a vector of length 5 filled with arbitrary integers from 0 to 10

NumPy: Basic Exercise-23 with Solution

Write a NumPy program to create a vector of length 5 filled with arbitrary integers from 0 to 10.

Sample Solution :

Python Code :

import numpy as np
x = np.random.randint(0, 11, 5)
print("Vector of length 5 filled with arbitrary integers from 0 to 10:")
print(x)

Sample Output:

Vector of length 5 filled with arbitrary integers from 0 to 10:
[ 0 10  2  0  6]                         

Pictorial Presentation:

NumPy: Create a vector of length 5 filled with arbitrary integers from 0 to 10.

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create a vector with values ​​from 0 to 20 and change the sign of the numbers in the range from 9 to 15.
Next: Write a NumPy program to multiply the values ​​of two given vectors.

What is the difficulty level of this exercise?