欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

tf.where 用法

发布时间:2025/4/5 编程问答 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 tf.where 用法 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

tf.where 应用到了张量的广播机制 张量的广播机制

tf.where(condition, x=None, y=None, name=None )
[if condition[k] =True 取 x[k] else 取 y[k]]
import tensorflow as tf c=tf.where([True, False, False, True], [1,2,3,4], [100,200,300,400]) print(c)c=tf.where([True, False, False, True], [1,2,3,4], [100]) print(c)c=tf.where([True, False, False, True], [1,2,3,4], 100) print(c)c=tf.where([True, False, False, True], 1, 100) print(c) tf.Tensor([ 1 200 300 4], shape=(4,), dtype=int32) tf.Tensor([ 1 100 100 4], shape=(4,), dtype=int32) tf.Tensor([ 1 100 100 4], shape=(4,), dtype=int32) tf.Tensor([ 1 100 100 1], shape=(4,), dtype=int32)

总结

以上是生活随笔为你收集整理的tf.where 用法的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。