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

TensorFlow中的张量值的条件分配

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

TensorFlow中的张量值的条件分配

TensorFlow
API中提供了几种比较运算符。

但是,在直接操纵张量时,没有什么等效于简洁的NumPy语法。你必须要使用个人的

comparison
where
assign
运营商执行相同的操作。

您的NumPy示例的等效代码是这样的:

import tensorflow as tfa = tf.Variable( [1,2,3,1] )    start_op = tf.global_variables_initializer()    comparison = tf.equal( a, tf.constant( 1 ) )    conditional_assignment_op = a.assign( tf.where (comparison, tf.zeros_like(a), a) )with tf.Session() as session:    # Equivalent to: a = np.array( [1, 2, 3, 1] )    session.run( start_op )    print( a.eval() )        # Equivalent to: a[a==1] = 0    session.run( conditional_assignment_op )    print( a.eval() )# Output is:# [1 2 3 1]# [0 2 3 0]

打印语句当然是可选的,它们只是用来演示代码是否正确执行。



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

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

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