码迷,mamicode.com
首页 > 其他好文 > 详细

tensorflow-累加accumulate_n,add_n

时间:2018-12-08 22:34:40      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:add   odi   author   ESS   code   ted   result   and   mon   

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Aug 27 11:16:32 2018 @author: myhaspl """ # TensorFlow and tf.keras import tensorflow as tf a = tf.constant([[1, 2], [3, 4]]) b = tf.constant([[5, 0], [0, 6]]) c=tf.ones([2,2],tf.int32) result1=tf.accumulate_n([a, b]) result2=tf.accumulate_n([a, b,c]) result3=tf.accumulate_n([a, b, c], shape=[2, 2], tensor_dtype=tf.int32) sess=tf.Session() with sess: print sess.run(result1) print sess.run(result2) print sess.run(result3)

[[ 6 ?2]
?[ 3 10]]
[[ 7 ?3]
?[ 4 11]]
[[ 7 ?3]
?[ 4 11]]

import tensorflow as tf
a = tf.constant([[1., 2.], [3., 4.]])
b = a*2-4
c= (b-1)*2

res=tf.add_n([a,b,c])

sess=tf.Session()
with sess:
    print sess.run(res)

[[-7. ?0.]
?[ 7. 14.]]

tensorflow-累加accumulate_n,add_n

标签:add   odi   author   ESS   code   ted   result   and   mon   

原文地址:http://blog.51cto.com/13959448/2327981

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!