How to Generate a 1-D Array with Random Integers


In this example we will show how to generate a 1-D array containing a specified number of random integers in Python NumPy.

Source Code

from numpy import random

# generate a 1-D array containing 6 random integers from 0 to 50
n = random.randint(50, size=6)

print(n)

Output:

[27 41  5 22  5 47]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments