I have an nd-numpy array of shape (m, 1,100,4) for which I would like to access the individual columns of the inner array (shape: (1,100,4)).
MWE: As example, say I have this:
import numpy as np
X = np.random.randn(2, 1, 5, 4)
X
array([[[[-0.40867508, 0.09331783, 1.26134307, -1.18900601],
[-0.79177772, 0.96738931, -0.33332772, 0.53130287],
[ 3.67290383, 0.30954936, 0.63221306, -0.64003826],
[-1.20878773, 1.21499506, 1.84995811, 0.15663168],
[-0.60648072, -0.30464852, -0.44044224, -4.46482868]]],
[[[-1.90531392, -0.47108517, 1.21177166, 0.09561669],
[ 3.21803694, 0.30611821, 1.71334417, 0.73383279],
[-1.12869017, -0.1497266 , -0.54913676, 0.36704922],
[ 0.5652546 , -0.75012341, -0.72496611, 1.12428097],
[-1.19727408, -0.13813127, 2.63948821, -0.37661527]]]])
where nested arrays are shaped (1,5,4). Then accessing the first columns of each nested array returns the entire array instead:
X[ :, 0]
array([[[-0.40867508, 0.09331783, 1.26134307, -1.18900601],
[-0.79177772, 0.96738931, -0.33332772, 0.53130287],
[ 3.67290383, 0.30954936, 0.63221306, -0.64003826],
[-1.20878773, 1.21499506, 1.84995811, 0.15663168],
[-0.60648072, -0.30464852, -0.44044224, -4.46482868]],
[[-1.90531392, -0.47108517, 1.21177166, 0.09561669],
[ 3.21803694, 0.30611821, 1.71334417, 0.73383279],
[-1.12869017, -0.1497266 , -0.54913676, 0.36704922],
[ 0.5652546 , -0.75012341, -0.72496611, 1.12428097],
[-1.19727408, -0.13813127, 2.63948821, -0.37661527]]])
My intention is to get a tuple, such that:
s,t,u,v = X[first_columns], X[second_columns], X[third_columns], X[fouth_columns]
such that:
s =[-0.40867508, -0.79177772, 3.67290383, -1.20878773, -0.60648072,
-1.90531392, 3.21803694, -1.12869017, 0.5652546, -1.19727408]