Python TypeError:无法理解数据类型,numpy.zeros
我在运行代码时出错。我收到的错误是:Python TypeError:无法理解数据类型,numpy.zeros,python,numpy,for-loop,typeerror,zero,Python,Numpy,For Loop,Typeerror,Zero,我在运行代码时出错。我收到的错误是: Traceback (most recent call last): File "/Users/penguin/PycharmProjects/Greatness/venv/Recipes.py", line 153, in <module> newRatios = np.zeros(count,count) TypeError: data type not understood Process finished with exit code
Traceback (most recent call last):
File "/Users/penguin/PycharmProjects/Greatness/venv/Recipes.py", line
153, in <module>
newRatios = np.zeros(count,count)
TypeError: data type not understood
Process finished with exit code 1
变量计数表示大约5000的整数值。很抱歉,我只能提供代码片段,而不是整个文件,但我不允许透露完整的文件
我不太清楚为什么会出现这个错误,我尝试了几种不同的方法来设置numpy零点数组和设置2D矩阵。请注意,我将numpy作为np导入,因此它被称为np。我正在使用python3,如果您对设置2D阵列和访问它有任何其他建议,并且比我这里的更好,我们也将不胜感激 您需要传入一个元组。尝试
np.zero((计数,计数))
有关此方法的更多文档,请参见:使用INT序列:
newRatios = np.zeros((count,count))
零的形状参数
接受整数或整数序列。请参阅。np.zeros
接受iterable作为形状参数。您需要将参数传递为np.zero((count,count))
。注意额外的括号。您当前正在做的是将count
作为shape
传入,然后将count
作为数据类型再次传入。它无法识别count
表示的数据类型,因此会出现错误
newRatios = np.zeros((count,count))