Swaping elements in 3d numpy array -


this question has answer here:

given 3d numpy array how swap first , last element of each 'pixel'

for example:

a = [[[15  3 61]     [56 27 22]     [48 32 29]     [38 21 50]     [28 54 37]]      [[47 27 35]     [52 34 12]     [18 56 48]     [ 8 34  1]     [37 27 38]]] 

i want array be:

a = [[[61  3 15]     [22 27 56]     [29 32 48]     [50 21 38]     [37 54 28]] 

and on

is there way without using loops?

you can reverse array along third axis a[..., ::-1]:

a = np.array([[[15,  3, 61],     [56, 27, 22],     [48, 32, 29],     [38, 21, 50],     [28, 54, 37]],     [[47, 27, 35],     [52, 34, 12],     [18, 56, 48],     [ 8, 34,  1],     [37, 27, 38]]])  a[..., ::-1] #array([[[61,  3, 15], #        [22, 27, 56], #        [29, 32, 48], #        [50, 21, 38], #        [37, 54, 28]],  #       [[35, 27, 47], #        [12, 34, 52], #        [48, 56, 18], #        [ 1, 34,  8], #        [38, 27, 37]]]) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -