Python 用零值替换 -inf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21049920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:54:54 来源:igfitidea点击:
Replace -inf with zero value
提问by user1821176
I have an array:
我有一个数组:
x = numpy.array([-inf, -inf, 37.49668579])
Is there a way to change the -inf values to just 0?
有没有办法将 -inf 值更改为 0?
采纳答案by pv.
There is:
有:
from numpy import inf
x[x == -inf] = 0
回答by YXD
Use isneginfhttp://docs.scipy.org/doc/numpy/reference/generated/numpy.isneginf.html#numpy.isneginf
使用isneginfhttp://docs.scipy.org/doc/numpy/reference/generated/numpy.isneginf.html#numpy.isneginf
x[numpy.isneginf(x)] = 0

