Home>

### python : How to create a random two-dimensional array NUMPY?

by means ``` NUMPY. ``` . I need an array of type ``` a= [[b, c], [d, e] ... [x, z]] ``` In order for in it, both positive and negative numbers.

• Answer # 1
``````Import NUMPY AS NP
np.random.uniform (Low= -100, High= 100, Size= (4, 2))
# output
Array ([
[-81.458, -81.53563001],
[14.38820047, 79.58667144],
[10.55146126, -73.9337667],
[12.82037855, 71.93397549]])
``````

either so

``````np.random.randint (-100, 100, (3, 2))
Array ([
[68, -63],
[41, 52],
[54, 85]])
``````

To go nuts, all the documentation lasts, did not see this function ... thanks

Resoxape2021-04-07 18:36:49

And in what section of the documentation this method is Uniform? I want to look about him yet. Is it creating an array or change?

Resoxape2021-04-07 18:40:38

@Resoxape, numpy.org/doc/stable/reference/random/generated/..., there is a site search. Creature.

entithat2021-04-07 18:41:49
• Answer # 2

in> ThisThe article was a moment with a random initialization of the weights of the neural network:

``````rows= 10
COLS= 2.
Array= 2 * numpy.random.random ((Rows, Cols)) -1
Print (Array)
``````

Possible conclusion:

``````Array ([[-0.90498638, 0.49846144],
[0.65269211, -0.83121061],
[0.03048237, 0.27927699],
[0.72069673, -0.81232947],
[0.27523583, 0.95059816],
[0.02586882, 0.96637237],
[0.88832145, -0.14137144],
[-0.39758786, 0.43305011],
[0.32713238, -0.0213639],
[-0.86635081, -0.63139956]])
``````

Also an important quote from it:

Note that it is initialized randomly, and average The value is zero. This costs a rather complicated theory. While Just take it as a recommendation.