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)
?
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.
NewZ = np.max(Z, axis=2)would yield aNewZ.shapeof(138, 112), for example.(138, 112, 123)has1901088elements. An array of shape(138, 112)has only15456elements. So which15456elements of the original array do you want to end up in the new array?