tf.reduce_sum() and tf.where()的用法

import tensorflow as tf
import numpy as np
sess=tf.Session()
a=np.ones((5,6))
c=tf.cast(tf.reduce_sum(a, axis=1),tf.bool) # tf.reduce_sum 表示按照axis方向求和
c=sess.run(c)
print('c=',c)
print('c.shape',c.shape)
k=tf.where(c) # 因为返回的是索引值为列表中
k=sess.run(k)
print('k=',k)
print('k.shape=',k.shape)
k_compare=tf.where(c)[:, 0]
k_compare=sess.run(k_compare)
print('k_compare=',k_compare)
print('k_compare.shape=',k_compare.shape)

结果如下:

猜你喜欢

转载自www.cnblogs.com/tangjunjun/p/11968519.html