Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy.nan_to_num - 'nan' keyword not recorgnized

When you try to replace nan value with a custom numeric value using following code,

np.nan_to_num(exp_allowance,nan=9999.99) 

it produces following error:

typeerror: nan_to_num() got an unexpected keyword argument 'nan'
like image 777
Prish Avatar asked Jan 10 '20 21:01

Prish


People also ask

How to replace NaN in NumPy?

In NumPy, to replace missing values NaN ( np. nan ) in ndarray with other numbers, use np. nan_to_num() or np. isnan() .

How to replace NaN in array Python?

nan_to_num() function is used when we want to replace nan(Not A Number) with zero and inf with finite numbers in an array. It returns (positive) infinity with a very large number and negative infinity with a very small (or negative) number.


2 Answers

After going through several blogs and no answers to it, I discovered that I was using obsolete numpy version.This specific argument is only supported in numpy version 1.17 and above. Those who are facing this issue, check your numpy version:

import numpy
numpy.version.version

if it is below 1.17 then update it the latest using,

pip install numpy --upgrade

It will work.

like image 189
Prish Avatar answered Nov 15 '22 11:11

Prish


The command to upgrade should be this:

pip install --upgrade numpy

The --upgrade argument comes before the module name. And if you are using it for a specific Python version, the code would be:

python37 -m pip install --upgrade numpy
like image 21
Pratyush Tripathy Avatar answered Nov 15 '22 09:11

Pratyush Tripathy