Slicing is basically extracting particular set of elements from an array. It is pretty much similar to the one which is there in the list as well. For example: We have an array and we need a particular element (say 3) out of a given array.
import numpy as np
a=np.array([(1,2,3,4),(3,4,5,6)])
print(a[0,2])
Output – 3
Here, the array(1,2,3,4) is your index 0 and (3,4,5,6) is index 1 of the python numpy array. Therefore, we have printed the second element from the zeroth index.
Taking one step forward, let’s say you need the 2nd element from the zeroth and first index of the array.
import numpy as np
a=np.array([(1,2,3,4),(3,4,5,6)])
print(a[0:,2])
Output –[3 5]