0

I have a numpy array Z such that:

Z.shape

#Out[1]:
    (138, 112, 123)

How do I transform Z into a new array NewZ, such that:

NewZ.shape

#Out[2]:
    (138, 112)

?

3
  • 3
    What operation do you want performed on the dimension you want removed? NewZ = np.max(Z, axis=2) would yield a NewZ.shape of (138, 112), for example. Commented Aug 25, 2015 at 18:59
  • 1
    An array of shape (138, 112, 123) has 1901088 elements. An array of shape (138, 112) has only 15456 elements. So which 15456 elements of the original array do you want to end up in the new array? Commented Aug 25, 2015 at 19:26
  • @DolphinGenomePyramids: Can you edit the question to clarify what sort of reduction operation you're looking for? Commented Aug 26, 2015 at 18:30

1 Answer 1

2

Removing a dimension means removing information, so you'll have to decide on a rule for projecting the original data down into a lower number of dimensions.

Suppose we have

import numpy as np
Z = np.random.random((138, 112, 123))

Here are two examples, both yielding a NewZ.shape of (138, 112):

  • NewZ = np.max(Z, axis=2), which takes the largest element of the last axis.
  • NewZ = Z[:,:,0], which takes the first element of the last axis.
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.