栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

TensorFlow:沿轴的张量的最大值

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

TensorFlow:沿轴的张量的最大值

tf.reduce_max()
运营商提供的正是这种功能。默认情况下,它计算给定张量的全局最大值,但您可以指定的列表
reduction_indices
,其含义与
axis
NumPy中的含义相同。要完成您的示例:

x = tf.constant([[1, 220, 55], [4, 3, -1]])x_max = tf.reduce_max(x, reduction_indices=[1])print sess.run(x_max)  # ==> "array([220,   4], dtype=int32)"

如果使用计算argmax

tf.argmax()
,可以获取从不同的张量的值
y
通过压平
y
使用
tf.reshape()
,转换argmax索引到矢量索引如下,并使用
tf.gather()
以提取适当的值:

ind_max = tf.argmax(x, dimension=1)y = tf.constant([[1, 2, 3], [6, 5, 4]])flat_y = tf.reshape(y, [-1])  # Reshape to a vector.# N.B. Handles 2-D case only.flat_ind_max = ind_max + tf.cast(tf.range(tf.shape(y)[0]) * tf.shape(y)[1], tf.int64)y_ = tf.gather(flat_y, flat_ind_max)print sess.run(y_) # ==> "array([2, 6], dtype=int32)"


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/645186.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号