How to Generate a 2-D Array of Random Integers in NumPy


In this example we will show how to create a 2-D array of random integers in Python NumPy.

Source Code

from numpy import random

# generate a 2-D array with 4 rows, each row containing 6 random integers from 0 to 50:
n = random.randint(50, size=(4, 6))

print(n)

Output:

[[ 7 30 40 46 28  1]
 [13 47 34 32 37 42]
 [ 4 35 38 42 44 46]
 [27  3 37 12 32 49]]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments