How can you swap the first and third channel of the array of shape (3,3,3)
img = np.arange(333).reshape(3,3,3)
how img[::-1] work??
How can you swap the first and third channel of the array of shape (3,3,3)
img = np.arange(333).reshape(3,3,3)
how img[::-1] work??
hey @lgoyal50_be19 ,
here -1 works just like a stepsize , the way you use in range function.
so img[:: stepsize ] means covering the data from index 0 to last index if stepsize is positive and covering the data from last index to index 0 if stepsize is negative.
So with -1 as stepsize , it goes in reverse direction.
for example a = [ [1,2,3],[3,2,1],[4,5,6] ]
if it would be a[ :: 1 ] , numpy would itself take default values as a[ 0:3:1 ] and will print the same array.
if it would be a[ :: 2 ] , numpy would itself take default values as a[ 0:3:2 ] and will print [ [1,2,3],[4,5,6] ] , only data at index 0 and 2 as stepsize is 2.
Similarly,
if it would be a[ ::-1 ] , numpy would itself take default values as a[ 3:0:-1 ] and will print the same array in reverse order. i.e. [[4,5,6],[3,2,1],[1,2,3]]
I hope this would have helped you understand it more properly.
Thank You and Happy Learning
.