[Numpy-discussion] 2D Arrays column operations

Travis Oliphant oliphant@ee.byu....
Thu Mar 29 14:46:05 CDT 2007

Simon Berube wrote:

>   I am relatively new to Python/NumPy switching over from Matlab and
>while porting some of my matlab code for practice I ran into the
>following problem.
>Assume we have a 2D Matrix such that
>a = array([[1, 2, 3],
>               [4, 5, 6],
>               [7, 8, 9]])
>If I want the second row I can simply enough take
>c = a[1]
>However, I would like to do a similar operation on the columns of the
>2D Array. In matlab I could simply do
>c = a(:,2) to get the values array([2,5,8])

c = a[:,2]


More information about the Numpy-discussion mailing list