11

l would like to generate a random 3d array containing random integers (coordinates) in the intervalle [0,100].

so, coordinates=dim(30,10,2)

What l have tried ?

coordinates = [[random.randint(0,100), random.randint(0,100)] for _i in range(30)]

which returns

array([[97, 68],
       [11, 23],
       [47, 99],
       [52, 58],
       [95, 60],
       [89, 29],
       [71, 47],
       [80, 52],
       [ 7, 83],
       [30, 87],
       [53, 96],
       [70, 33],
       [36, 12],
       [15, 52],
       [30, 76],
       [61, 52],
       [87, 99],
       [19, 74],
       [37, 63],
       [40,  2],
       [ 8, 84],
       [70, 32],
       [63,  8],
       [98, 89],
       [27, 12],
       [75, 59],
       [76, 17],
       [27, 12],
       [48, 61],
       [39, 98]])

of shape (30,10)

What l'm supposed to get ?

dim=(30,10,2) rather than (30,10)

1 Answer 1

27

Use the size parameter:

import numpy as np
coordinates = np.random.randint(0, 100, size=(30, 10, 2))

will produce a NumPy array with integer values between 0 and 100 and of shape (30, 10, 2).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.