[SciPy-user] replacing numpy.inf in an array fast with 0.0 ?

Nils Wagner nwagner at iam.uni-stuttgart.de
Thu Nov 23 08:03:21 CST 2006


Robert wrote:
> I have a big array which contains some inf/nan's and want to replace them with 0.0 . How to do? - robert
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>   
from scipy import *

z = random.rand(10)
z[4] = nan
z[-1] = inf
print z
z[where(isinf(z))]=0.0
z[where(isnan(z))]=0.0
print z

Maybe there is a more efficient way.

Nils

 


More information about the SciPy-user mailing list