7

I need to flip 3D Array A shaped [m, n, k], along the Z axis. I need plane 0 (A[0,:,:]) to become k-1, plane 1 become k-2 plane and so on.

I need to do that on many array's, and loops are very slow.

I tried:

C = numpy.rot90(A,2)
C = flipud(A)
C = A[::-1]

I tried also rol and reshape, not what I needed.

For example: A is (3, 2, 2)

    A= np.array([[[ 1.01551435, -0.76494131],
 [ 0.56853752 , 1.94491724]],
[[-0.97433012 , 2.08134198],
 [-1.34997602 ,-0.33543117]],
[[ 0.54217072, -1.33470658],
 [-0.50179028, -0.66593918]]])

I need to reorder Z axis upside down:

[[ 0.54217072 -1.33470658]
 [-0.50179028 -0.66593918]]
[[-0.7703279   0.02402204]
 [-0.18006451 -0.37589744]]
[[ 1.01551435 -0.76494131]
 [ 0.56853752  1.94491724]]

Any ideas ?

4
  • 5
    Give a small example, say a 2x3x4 array, and what you want. Also indicate what is wrong with what you tried. I'm guessing A[:, :, ::-1] will do the trick. Commented Sep 6, 2016 at 21:19
  • @hpaulj 's suggestion is a good one try... a = np.arange(2*3*4).reshape(2,3,4) then use his rearrangement to make it clear if this is what you want. Commented Sep 6, 2016 at 21:49
  • Added example in the question Commented Sep 7, 2016 at 8:45
  • @hpaulj 's suggestion solved the problem. thanks Commented Sep 7, 2016 at 9:29

1 Answer 1

3

As @hpaulj suggested:

A = A[::-1, :, :]

print A.shape
print A

    (3L, 2L, 2L)

[[[ 0.54217072 -1.33470658]
  [-0.50179028 -0.66593918]]

 [[-0.97433012  2.08134198]
  [-1.34997602 -0.33543117]]

 [[ 1.01551435 -0.76494131]
  [ 0.56853752  1.94491724]]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.