gpt4 book ai didi

TensorFlow 相当于 numpy.all()

转载 作者:行者123 更新时间:2023-12-02 16:21:03 29 4
gpt4 key购买 nike

如标题所述,TensorFlow 是否存在与 numpy.all() 函数等效的函数来检查 bool 张量中的所有值是否为 True?实现此类检查的最佳方法是什么?

最佳答案

使用tf.reduce_all ,如下:

import tensorflow as tf
a=tf.constant([True,False,True,True],dtype=tf.bool)
res=tf.reduce_all(a)
sess=tf.InteractiveSession()
res.eval()

这将返回False

另一方面,这会返回True:

import tensorflow as tf
a=tf.constant([True,True,True,True],dtype=tf.bool)
res=tf.reduce_all(a)
sess=tf.InteractiveSession()
res.eval()

关于TensorFlow 相当于 numpy.all(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45736314/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com