Questions on migrating from Numeric/Scipy to Numpy
Robert Kern
robert.kern at gmail.com
Tue Mar 13 23:20:05 EDT 2007
vj wrote:
>> Note that the mask needs to be a bool array.
>
>>>> mask = zeros(5)
>>>> mask = zeros(5, numpy.int8)
>>>> mask[1] = True
>>>> mask[2] = True
>>>> a = zeros(5)
>>>> a[mask] = [100, 200]
>>>> a
> array([ 100., 100., 0., 0., 0.])
>
> I found this strange. It should just give an error if you try to use a
> mask array of non booleans.
No, it simply does something different. Boolean arrays apply as a mask. Integer
arrays apply as indices into the array.
--
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 Python-list
mailing list