将所有NAN值转换为TensForflow中的零值
我正在尝试将所有nan
值转换为零。我无法正确执行它!
以下是代码:也可在COLAB上使用:
import tensorflow as tf
import numpy as np
ts = tf.constant([[0,0]])
tx = tf.constant([[0,1]])
out = ts / (ts + fx)
out.numpy() # array([nan, 0.])
tf.math.is_nan(out).numpy() # array([ True, False]
out.numpy()[(tf.math.is_nan(out).numpy())] = 0
out.numpy() #array([nan, 0.])
” > out.numpy()应给出array([0。,0。])
I am trying to convert all nan
values to zero in my final results. I am not able to execute it properly!
The following is the code: also availvable on colab : link
import tensorflow as tf
import numpy as np
ts = tf.constant([[0,0]])
tx = tf.constant([[0,1]])
out = ts / (ts + fx)
out.numpy() # array([nan, 0.])
tf.math.is_nan(out).numpy() # array([ True, False]
out.numpy()[(tf.math.is_nan(out).numpy())] = 0
out.numpy() #array([nan, 0.])
out.numpy()
should give array([0., 0.])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改:
到:
Change:
To: