Python Numpy 数组:序列太大

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17688094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:55:15  来源:igfitidea点击:

Numpy array: sequence too large

pythonnumpy

提问by Matt

I have an array of size 11called 'wavelength' and a larger array of size ncalled 'MN'. And 'model' is an mby narray.

我有一个11称为“波长”的大小数组和一个n称为“MN”的更大大小的数组。'model' 是一个mbyn数组。

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.

我不知道该怎么办。我在网上其他地方看过,但找不到任何明显的实质内容。

采纳答案by HYRY

sequence too largeerror 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.

sequence too large错误意味着您正在创建一个维度大于 32 的多维数组。例如:np.empty([1]*33)将引发此错误。

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()

您确定要创建 > 32 维数组吗?如果要创建与 形状相同的空数组model[MN][i],则应使用:empty_like()