> Date: Thu, 09 Oct 2014 11:12:31 +0530
> From: suchith <suchithjn22(a)gmail.com>
> Subject: [Numpy-discussion] Extracting individual columns in Numpy
> To: numpy-discussion(a)scipy.org
> Message-ID: <54362047.10102(a)gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> How to extract individual columns from a numpy array?
> For example, consider this script
>
> import numpy as np
> a = np.array([[1,2,3],[4,5,6],[7,8,9]])
> a[0][:]
> a[:][0]
>
> Now both a[:][0] and a[0][:] are outputting the same result, i.e
> np.array([1,2,3]). If I want to extract the array [[1],[4],[7]] then
> what should I do? Is it possible to add this feature? If so, which
> file(s) should I edit?
>
> I know C,C++ and Python programming and I am new to open-source software
> development. Please help me.
>
Try:
In [2]: import numpy as np
In [3]: a = np.array([[1,2,3],[4,5,6],[7,8,9]])
In [4]: a[0][:]
Out[4]: array([1, 2, 3])
In [5]: a[:][0]
Out[5]: array([1, 2, 3])
In [6]: a[0,:]
Out[6]: array([1, 2, 3])
In [7]: a[:,0]
Out[7]: array([1, 4, 7])
Syntax is different for numpy arrays.
Regards,
Juan