I'm trying to extract a row from a Numpy array using
t = T[153,:]
But I'm finding that where the size of T
is (17576, 31), the size of t
is (31,) - the dimensions don't match!
I need t
to have the dimensions (,31) or (1,31) so that I can input it into my function. I've tried taking the transpose, but that didn't work.
Can anyone help me with what should be a simple problem?
Many thanks
You can extract the row with a slice notation:
t = T[153:154,:] # will extract row 153 as a 2d array
Example:
T = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
T[1,:]
# array([5, 6, 7, 8])
T[1,:].shape
# (4,)
T[1:2,:]
# array([[5, 6, 7, 8]])
T[1:2,:].shape
# (1, 4)
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