hit counter

Timeline

My development logbook

Slicing Magic

Original post: http://stackoverflow.com/a/9858902/58129

Given this

1
2
3
4
5
>>> a  = array([[1,2,3,4], [5,6,7,8], [9, 10,11,12]])
>>> a
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12]])

You can use the following code to extract data in the first and second column as such

1
2
3
4
5
6
>>> list1 = a[:,0]
>>> list1
array([1, 5, 9])
>>> list1 = a[:,1]
>>> list1
array([ 2,  6, 10])

Slicing documentation: http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#basic-slicing