[SciPy-dev] extract and where
eric jones
eric at enthought.com
Sun Sep 21 04:37:46 EDT 2003
extract has the following signature:
>>> help(extract)
Help on function extract in module __main__:
extract(arr, mask)
1D array of those elements of ravel(arr) where ravel(mask) is true.
This is backward from most of the Numeric routines where the condition
(mask) array comes first (where, compress, and maybe others). Any
objections to reversing these?
Also, the one argument form of where() included in numarray would be
useful to have in SciPy while we are still relying on Numeric. Should
we wait until after 0.2, or go ahead and add this?
From the numarray docs:
Starting with numarray-0.6, where supports a one parameter form that is
equivalent to nonzero but reads better:
>>> where(arange(10) % 2)
(array([1, 3, 5, 7, 9]),) # indices where expression is true
< the following would have to use take() instead of indexing while we
are still relying on Numeric>
Like nonzero, the one parameter form of where can be used to do array
indexing:
>>> a = arange(10,20)
>>> a[ where( a % 2 ) ]
array([11, 13, 15, 17, 19])
Note that for array indices which are boolean arrays, using where is not
necessary but is still OK:
>>> a[(a % 2) != 0]
array([11, 13, 15, 17, 19])
>>> a[where((a%2) != 0)]
array([11, 13, 15, 17, 19])
eric
More information about the SciPy-Dev
mailing list