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)
To create a numpy array of specific shape with random values, use numpy. random. rand() with the shape of the array passed as argument.
In order to generate random array of integers in Java, we use the nextInt() method of the java. util. Random class. This returns the next random integer value from this random number generator sequence.
The numpy.random.rand() function creates an array of specified shape and fills it with random values. Syntax : numpy.random.rand(d0, d1, ..., dn) Parameters : d0, d1, ..., dn : [int, optional]Dimension of the returned array we require, If no argument is given a single Python float is returned.
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With