import tensorflow as tf
a = tf.constant([[-1, 2, 3],
[2, -3, 4],
[5, 6, -7]], dtype=tf.float32)
d = tf.ones(shape=[3, 3], name='d')
e = tf.zeros(shape=[3, 3], name='e')
b = tf.where(a < 0, d, e)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(b))
# output
# [[1. 0. 0.]
# [0. 1. 0.]
# [0. 0. 1.]]
tensorflow 生成一个tensor的mask
最新推荐文章于 2024-01-11 21:42:01 发布
本文展示了一个使用TensorFlow进行条件操作的例子,具体为根据矩阵元素的正负值选择填充1或0,通过运行会话并打印结果,展示了TensorFlow中where函数的应用。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
TensorFlow-v2.15
TensorFlow
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

1261

被折叠的 条评论
为什么被折叠?



