[Numpy-discussion] Nonzero behaving strangely?
Matthieu Brucher
matthieu.brucher at gmail.com
Thu Mar 17 18:19:42 EDT 2011
Hi,
Did you try np.where(res[:,4]==2) ?
Matthieu
2011/3/17 santhu kumar <mesanthu at gmail.com>
> Hello all,
>
> I am new to Numpy. I used to program before in matlab and am getting used
> to Numpy.
>
> I have a array like:
> res
> array([[ 33.35053669, 49.4615004 , 44.27631299, 1. , 2.
> ],
> [ 32.84263059, 50.24752036, 43.92291659, 1. , 0.
> ],
> [ 33.68999668, 48.90554673, 43.51746687, 1. , 0.
> ],
> [ 34.11564931, 49.77487763, 44.83843076, 1. , 0.
> ],
> [ 32.4641859 , 48.65469145, 45.09300791, 1. , 3.
> ],
> [ 32.15428526, 49.26922262, 45.92959026, 1. , 0.
> ],
> [ 31.23860825, 48.21824628, 44.30816331, 1. , 0.
> ],
> [ 30.71171138, 47.45600573, 44.9282456 , 1. , 0.
> ],
> [ 30.53843426, 49.07713258, 44.20899822, 1. , 0.
> ],
> [ 31.54722284, 47.61953925, 42.95235178, 1. , 0.
> ],
> [ 32.44334635, 48.10500653, 42.51103537, 1. , 0.
> ],
> [ 31.77269609, 46.53603145, 43.06468455, 1. , 0.
> ],
> [ 30.1820843 , 47.80819604, 41.77667819, 1. , 0.
> ],
> [ 30.78652668, 46.82907769, 40.38586451, 1. , 0.
> ],
> [ 30.05963091, 46.84268609, 39.54583693, 1. , 0.
> ],
> [ 31.75239177, 47.22768463, 40.00717713, 1. , 0.
> ],
> [ 30.94617127, 45.76986265, 40.68226643, 1. , 0.
> ],
> [ 33.20069679, 47.42127403, 45.66738249, 1. , 0.
> ],
> [ 34.39608116, 47.25481126, 45.4438599 , 1. , 0.
> ]])
>
> The array is 19X5.
> When I do:
> nid = (res[:,4]==2).nonzero()
> nid tuple turns out to be empty. But the very first row satisfies the
> criteria.
>
> nid = (res[:,4]==3).nonzero(), works out and finds the 5th row.
>
> Am i doing something wrong?
> I basically want to find the rows whose fifth coloumn(4th in numpy matrix
> format) is 2.
>
> Any suggestions?
> Thanks
> Santhosh
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110317/3b48f06c/attachment.html>
More information about the NumPy-Discussion
mailing list