[PYTHON MATRIX-SIG] Find/where function

Chris Chase SRM chris.chase@jhuapl.edu
Mon, 28 Oct 1996 12:13:11 -0500


I would like to see the following convenience function added for
returning the indices of nonzero array elements.  I would prefer to
call this "where" instead of "find" but "where" is already taken.

def find(a):
    return compress(a.flat,arange(product(a.shape)))

Example,

b = reshape(arange(24),(2,3,4))
find(b%2)

Chris

=================
MATRIX-SIG  - SIG on Matrix Math for Python

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