数组的索引
import numpy as np arr1 = np.array([10,20,30,40]) arr1
Out[1]:
array([1, 2, 3, 4])
In [2]:
print(arr1[0]) print(arr1[1]) print(arr1[2]) print(arr1[3])
1 2 3 4
In [4]:
print(arr1[5])
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-4-37aaa1982335> in <module>() ----> 1 print(arr1[5]) IndexError: index 5 is out of bounds for axis 0 with size 4
In [5]:
print(arr1[-1]) print(arr1[-2]) print(arr1[-3]) print(arr1[-4])
4 3 2 1
In [6]:
print(arr1[-5])
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-6-9389ae9c77b9> in <module>() ----> 1 print(arr1[-5])