In Basic slicing of numpy array http://docs.scipy.org/doc/numpy-1.5.x/reference/arrays.indexing.html#basic-slicing,
I found the following rule which does not work for the example I shown below.
Rule: Assume n is the number of elements in the dimension being sliced. Then, if i is not given it defaults to 0 for k > 0 and n for k < 0 . If j is not given it defaults to n for k > 0 and -1 for k < 0 . If k is not given it defaults to 1. Note that :: is the same as : and means select all indices along this axis.
What I understood : This can be prioritized as top to down :
a)If k is not given it defaults to 1.
b)If j is not given it defaults to n for k > 0 and -1 for k < 0 .
c)if i is not given it defaults to 0 for k > 0 and n for k < 0.
Now let's see the example. Basically what I am doing is to take a 3d array and print it bottom up . Layer with largest index comes first and then the smaller one. Please look at code for better understanding.
import numpy as np
b= np.arange(24).reshape(2,3,4)
print "Here is the input :"
print b
print
print "Here is what is desired output :"
print b[::-1 , :: ,::]
print
print "Here is what I want to get desired output by a different way using above rule :"
print b[2:-1:-1 , :: , ::]
Output :
Here is the input :
[[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]
Here is what is desired output :
[[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]]
Here is what I want to get desired output by a different way using above rule :
[]
Is b[::-1 , :: ,::] not same as b[2:-1:-1 , :: , ::] by above rule?