[PYTHON MATRIX-SIG] Simple Questions...

Jim Hugunin hugunin@mit.edu
Fri, 23 Aug 1996 12:19:20 -0400

I know I'm violating nettiquette by forwarding personal mail to the
list, but given the recent trend towards esoteric discussion on the
list, I thought that this might help encourage people to ask simple
questions.  My apologies to David. :-)

David Ascher wrote:
> In the numeric package, is there a way to go from
>         a = array([1,2,2,1,2])
>         via something like a.indices(2) ==> (1,2,4) ?
>         [by extension to the index() method on lists].
> I get lost between select, choose, etc.

>>> from Numeric import *
>>> a = array([1,2,2,1,2])
>>> nonzero(equal(a,2))
1 2 4

equal will return an array that is one everywhere the arrays are equal
and zero everywhere else.

nonzero will return the indices of those elements in the array which are
non-zero. (nonzero is implemented using repeat, but you shouldn't really
need to know that).


MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org