python中以数组形式访问标量
我已将数组中的标量0D定义为python中以数组形式访问标量,python,arrays,tensor,Python,Arrays,Tensor,我已将数组中的标量0D定义为 import np as numpy x = np.array(1) 如何访问这个“标量”,是否可以使用索引 In []: x[0] --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-inp
import np as numpy
x = np.array(1)
如何访问这个“标量”,是否可以使用索引
In []: x[0]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-42-2f755f117ac9> in <module>
----> 1 x[0]
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
其次,我将向量1D定义为
y = np.array([0,1,2,3,4])
其中y.shape
方法返回(5,)
添加冒号似乎令人困惑-是否可以通过shape
方法配置其显示
y = np.array([0,1,2,3,4])