[Numpy-discussion] Memory errors
Francesc Altet
faltet at carabos.com
Fri Oct 6 08:46:43 CDT 2006
A Divendres 06 Octubre 2006 15:30, Vikalpa Jetly va escriure:
> avoid the memory error. Related question is that I need to test for
> multiple conditions on the same array and set values to 1 or 0. I see that
> statements like b[a>200 or a<50] = 1 do not work. So is the way to do this
> simply to run a separate statement in the form b[condition]= 1 for each
> test?
For this, you have to use the binary operators instead of logical ones. For
example:
In [43]: a=numpy.arange(10)
In [44]: b=numpy.arange(10)
In [45]: b[(a < 2) | (a > 8)] = 1
In [46]: b
Out[46]: array([1, 1, 2, 3, 4, 5, 6, 7, 8, 1])
[be sure to use parentesizes appropriately]
Cheers,
--
>0,0< Francesc Altet http://www.carabos.com/
V V Cárabos Coop. V. Enjoy Data
"-"
More information about the Numpy-discussion
mailing list