mercredi 21 octobre 2020

avoid for loop in python normal(size={}))

My goal is to create an array where each elemet is normal(size={})) of each element of it.

I am trying to oprimize:

it = 2 ** arange(6, 25)
M = zeros(len(it))
for x in range(len(it)):
    M[x] = (normal(size=it[x]))

I have these not working so far:

N = zeros(len(it))
it = 2 ** arange(6, 25)
N = (normal(size=it))

Further I tried:

N = (normal(size=it[:]))

Provided my data, I believe that such a manual work, or for loop is really inefficient, so I am trying to come up with vectorized operations.

i receive:

File "mtrand.pyx", line 1335, in numpy.random.mtrand.RandomState.normal
  File "common.pyx", line 557, in numpy.random.common.cont
ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.



Aucun commentaire:

Enregistrer un commentaire