# NumPy array and index - How to get the value of a given index

You can get the value of a NumPy array by an index.

import numpy

a = numpy.array([2, 1, 3])

print(a[0])  # 2
print(a[1])  # 1
print(a[2])  # 3
print(a[3])  # IndexError: index 3 is out of bounds for axis 0 with size 3
print(a[-1])  # 3
print(a[-2])  # 1
print(a[-3])  # 2
print(a[-4])  # IndexError: index -4 is out of bounds for axis 0 with size 3


There is no value of index 3. Surprisingly, the values of minus indexes exist but index -4 raises IndexError exception.

So the indexes of NumPy array are -3, -2, -1, 0, 1, 2.