I realize that arr[::-1] returns a reversed view for arr. Further arr[st_index:end_index:increment] is a compact syntax for indexing while creating view. (BTW what is this way of indexing called?)
So if I have code like:
arr = np.array(range(10))
print(arr) #prints: [0 1 2 3 4 5 6 7 8 9]
Now, if I want to see the arr as reversed I can try (I don’t need to subtract 1 from len(arr)):
arr[len(arr)-1: 0: -1] #This gives o/p as: array([9, 8, 7, 6, 5, 4, 3, 2, 1])
The first element was not selected, which was expected. And if I change 0 to -1, i.e, if I try: arr[len(arr)-1: -1: -1]
OR even arr[:-1:-1]
, I get an empty array.
Apparently I get the reversed array view by: arr[::-1]
Q: How is this working? If I do not specify the first two arguments how does it infer that it needs to continue till 0? In fact it is just interpreting that it needs to go till the boundary as arr[::1] gives normal array.
Is this just coded as a special case or is there something more going on? And is there a way to get reversed array view by explicitly specifying the three expressions in indexing. i.e., are there any values for expr1, expr2, expr3 which can reverse arr in arr[expr1:expr2:expr3]
?