numpy-索引

来源:互联网 发布:澳门银河网络平台 编辑:程序博客网 时间:2024/05/16 12:42

1.numpy中的多维数组和普通的python数组都是从0开始索引。

2.numpy中多维数组第一个值是该数组的行

3.多维数组是一个n列m行的矩阵(shape)

>>> import numpy as np
>>> x = np.array([[1,2,3], [4,5,6]])
>>> x[1,2]
6
>>> x[1]
array([4, 5, 6])
>>> x[2,2]
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
IndexError: index 2 is out of bounds for axis 0 with size 2
>>>



0 0