[SciPy-user] extract array elements whis where() output
Robert Kern
robert.kern at gmail.com
Wed Jun 21 16:12:55 EDT 2006
Steve Schmerler wrote:
> First of all: what's better (a) post this only on the numpy list (b)
> only on the scipy list (I think many scipy users may find the answer to
> questions like this one interesting) or (c) post on both.
Probably (a). (c) should never be done except for single-shot announcements.
> I can't extract elements from array x with a mask array of indices but
> x.take (Numeric style works). I'm sure that I have done such things
> before .... and they worked.
>
> In [58]: x
> Out[58]: array([0, 0, 1, 2, 3, 0, 0, 9])
>
> In [59]: mask=where(x!=0.0)[0]
>
> In [60]: mask
> Out[60]: array([2, 3, 4, 7])
>
> In [61]: x.take(mask)
> Out[61]: array([1, 2, 3, 9])
>
> In [62]: x(mask)
> ---------------------------------------------------------------------------
> exceptions.TypeError Traceback (most
> recent call last)
>
> /home/elcorto/ode_testdata/<ipython console>
>
> TypeError: 'numpy.ndarray' object is not callable
You meant x[mask], not x(mask).
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the SciPy-User
mailing list