Numpy array: sequence too large

Question:

I have an array of size 11 called ‘wavelength’ and a larger array of size n called ‘MN’. And ‘model’ is an m by n array.

I’m doing this:

for i in xrange(10+len(wavelength)-2):
  y=np.empty(model[MN][i],float)

and getting this as an error:

  File "test_prog.py", line 658, in <module>
    y=np.empty(model[MN][i],float)
ValueError: sequence too large; must be smaller than 32

I’m not sure what to do about that. I’ve looked elsewhere online but I can’t find anything of obvious substance.

Asked By: Matt

||

Answers:

sequence too large error means that you are creating a multidimension array that has a dimension larger than 32. For example: np.empty([1]*33) will raise this error.

Are you sure you want to create >32 dimension array? If you want to create an empty array the same shape as model[MN][i], you should use: empty_like()

Answered By: HYRY

use:

empty_like()

In your case it should be:

y=np.empty_like(model[MN][i],float)
Answered By: javed
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.