Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace -inf with zero value

I have an array:

x =  numpy.array([-inf, -inf, 37.49668579]) 

Is there a way to change the -inf values to just 0?

like image 776
user1821176 Avatar asked Jan 10 '14 16:01

user1821176


People also ask

How do I replace #value with 0 in Excel?

Step 1: Select the range that you will work with. Step 2: Press the F5 key to open the Go To dialog box. Step 3: Click the Special button, and it opens the Go to Special dialog box. Step 6: Now just enter 0 or any other value that you need to replace the errors, and press Ctrl + Enter keys.

How do you replace zero values in R?

To replace zero with previous value in an R data frame column, we can use na. locf function of zoo package but to apply this we first need to replace the zero values with NA.


2 Answers

There is:

from numpy import inf x[x == -inf] = 0 
like image 151
pv. Avatar answered Sep 20 '22 21:09

pv.


Use isneginf http://docs.scipy.org/doc/numpy/reference/generated/numpy.isneginf.html#numpy.isneginf

x[numpy.isneginf(x)] = 0 
like image 32
YXD Avatar answered Sep 21 '22 21:09

YXD