Python 使用具有大量维度的numpy.array
如果尝试在numpy中创建具有大量维度的数组,则会引发异常:Python 使用具有大量维度的numpy.array,python,numpy,Python,Numpy,如果尝试在numpy中创建具有大量维度的数组,则会引发异常: In [1]: import numpy as np In [2]: a = np.zeros((1,) * 33) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipy
In [1]: import numpy as np
In [2]: a = np.zeros((1,) * 33)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-32dc30f6e439> in <module>()
----> 1 a = np.zeros((1,) * 33)
ValueError: sequence too large; must be smaller than 32
[1]中的:将numpy作为np导入
在[2]中:a=np.zero((1,)*33)
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
---->1A=np.0((1,)*33)
ValueError:序列太大;必须小于32
有什么简单的解决办法吗
numpy不允许创建这样的数组的原因是什么 来自:
您可以更改这些定义,并从源代码构建一个不兼容的版本,以满足您的需要。如果有那么多维度,您可能会有大量长度为1的维度,您可能会删除这些维度,或者您将难以将这么多的数组安装到RAM中
numpy.zero([2]*33)
甚至不适合32位地址空间。@user2357112是的,我有很多长度为1的维度,不,我不能删除them@user2357112拥有这些维度简化了许多操作,(主要原因)许多代码已经依赖于它
/*
* There are several places in the code where an array of dimensions
* is allocated statically. This is the size of that static
* allocation.
*
* The array creation itself could have arbitrary dimensions but all
* the places where static allocation is used would need to be changed
* to dynamic (including inside of several structures)
*/
#define NPY_MAXDIMS 32
#define NPY_MAXARGS 32