按索引调用多维NumPy数组时的TypeError

时间:2016-01-28 08:50:41

标签: python arrays numpy multidimensional-array ipython

我无法使代码看起来正常......

import numpy as np

test = np.zeros(3,2)

print(test[0])
---------------------------------------------------------------------------
TypeError                                 
Traceback (most recent call last)

<ipython-input-35-81513f7c30bf> in <module>()

      1 import numpy as np

----> 2 test = np.zeros(3,2)

      3 print(test[0])

TypeError: data type not understood

1 个答案:

答案 0 :(得分:1)

使形状成为元组:

test = np.zeros((3,2))
print(test[0])

输出:

[ 0.  0.]