[Numpy-discussion] Why does argwhere return column vector?
Stéfan van der Walt
stefan@sun.ac...
Tue May 27 03:15:10 CDT 2008
Hi Mark
2008/5/27 mark <markbak@gmail.com>:
> I don't understand why argwhere returns a column vector when I apply
> it to a row vector:
>
>>>> a = arange(5)
>>>> argwhere(a>1)
> array([[2],
> [3],
> [4]])
Each row of the result is a coordinate into your array. So if you had
a = np.arange(12).reshape((4,3))
then you'd get
In [54]: np.argwhere(a>5)
Out[54]:
array([[2, 0],
[2, 1],
[2, 2],
[3, 0],
[3, 1],
[3, 2]])
If you want to grab the elements larger than 5, just do
a[a>5]
Regards
Stéfan
More information about the Numpy-discussion
mailing list