【发布时间】:2014-01-29 18:10:00
【问题描述】:
我有一个数组:
x = numpy.array([-inf, -inf, 37.49668579])
有没有办法将 -inf 值更改为 0?
【问题讨论】:
标签: python arrays numpy infinity
我有一个数组:
x = numpy.array([-inf, -inf, 37.49668579])
有没有办法将 -inf 值更改为 0?
【问题讨论】:
标签: python arrays numpy infinity
有:
from numpy import inf
x[x == -inf] = 0
【讨论】:
from numpy import inf 吗?
使用isneginfhttp://docs.scipy.org/doc/numpy/reference/generated/numpy.isneginf.html#numpy.isneginf
x[numpy.isneginf(x)] = 0
【讨论】:
使用numpy.nan_to_num 可能更容易、更灵活:
numpy.nan_to_num(x, neginf=0)
Out[1]: array([ 0. , 0. , 37.49668579])
【讨论】: