[英]Using numpy.array with large number of dimensions
如果您嘗試在numpy中創建具有大量維度的數組,則會引發異常:
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
這有什么簡單的解決方法嗎?
numpy不允許創建此類數組的原因是什么?
來自NumPy源代碼 :
/*
* 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
您可以更改這些定義並從源代碼構建符合您需求的不兼容版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.