[Numpy-discussion] Selecting columns of a matrix
Keith Goodman
kwgoodman at gmail.com
Wed Jun 21 09:13:54 CDT 2006
On 6/20/06, Bill Baxter <wbaxter at gmail.com> wrote:
> >>> a[:,num.where(v>0.5)[0]]
> array([[1, 2, 4],
> [6, 7, 9]])
>
> I'll put that up on the Matlab->Numpy page.
That's a great addition to the Matlab to Numpy page.
But it only works if v is a column vector. If v is a row vector, then
where(v.A > 0.5)[0] will return all zeros. So for row vectors it
should be where(v.A > 0.5)[1].
Or, in general, where(v.flatten(1).A > 0.5)[1]
More information about the Numpy-discussion
mailing list