Имам масив:
x = numpy.array([-inf, -inf, 37.49668579])
Има ли начин да промените стойностите -inf само на 0?
Имам масив:
x = numpy.array([-inf, -inf, 37.49668579])
Има ли начин да промените стойностите -inf само на 0?
Има:
from numpy import inf
x[x == -inf] = 0
from numpy import inf
?
- person skjerns; 12.06.2020
X[~np.isfinite(X)]
= 0 или x[numpy.isneginf(x)] = 0
както във втория отговор
- person Adiel Loinger; 06.07.2020
Може би дори по-лесно и по-гъвкаво за използване numpy.nan_to_num
:
numpy.nan_to_num(x, neginf=0)
Out[1]: array([ 0. , 0. , 37.49668579])
Използвайте isneginf
http://docs.scipy.org/doc/numpy/reference/generated/numpy.isneginf.html#numpy.isneginf
x[numpy.isneginf(x)] = 0