Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert 'np.inf' to an integer type?

Tags:

python

int

numpy

I want to convert the return type of np.inf to int, by default it returns float type.

I have tried the followings, but both give erros.

int(np.inf)

OverflowError: cannot convert float infinity to integer

(np.inf).astype(int64)

AttributeError: 'float' object has no attribute 'astype'

like image 571
Ali Khan Avatar asked Oct 22 '25 15:10

Ali Khan


1 Answers

Unfortunately as the comments suggest no there isn't, but if you know the integer type you want, you can use np.iinfo and pick max or min

np.iinfo(np.int32).max  # ---- 2147483647

np.iinfo(np.int32).min  # ---- -2147483648

np.iinfo(np.int64).max  # ---- 9223372036854775807

np.iinfo(np.int64).min  # ---- -9223372036854775808
like image 172
NaN Avatar answered Oct 25 '25 04:10

NaN