I have a numpy array of size 28x28x60000. Observe the following:
>>> X.shape
(28, 28, 60000)
>>> X[:][:][0].shape
(28, 60000)
Shouldn't X[:][:][0] be an array of size 28x28? We are including every component from the first two dimensions (28 each), but only the 0th entry from the third.
What is going on here?
You slicing wrong. Slice X[:] return the copy of the original array. So your slicing could be interpreted as 1st copy of the X, then another copy of the X and then get first element which has 28x60000 shape. So you need to call X[:,:,0]. Example:
import numpy as np
X = np.random.randn(28,28,60000)
In [257]: X[:,:,0].shape
Out[257]: (28, 28)
You could compare your X[:] and X[:][:] statements with all
In [261]: (X[:] == X[:][:]).all()
Out[261]: True
X[:] indexes into all values from all dimensions, not just the first. So X[:][:] is identical to X
To get your result, you simply write X[:,:,0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With