Reputation: 2785
In python, I have a 2x1 array
a=array([[ 0, 4, 8, 12, 16],
[ 0, 8, 16, 24, 32]])
When I extract a column vector
c=a[:,1]
C becomes a 1x2 array, and I wish it to be a 2x1 array. Applying transpose does not seems to do the trick.
Any suggestions?
Thanks
Upvotes: 1
Views: 5026
Reputation: 68682
Other options include:
import numpy as np
c = a[:,1]
and then access the data with the desired shape using:
c[:,np.newaxis]
or
c[:,None]
Upvotes: 1
Reputation: 212885
After
c=a[:,1]
c
is now:
array([4, 8])
i.e. a 1D array (so even not 1x2).
If you want it a 2x1 array, try this:
c = a[:,1:2]
it will become:
array([[4],
[8]])
Upvotes: 8