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)

结果如下:

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

 

 

相关文章:

  • 2021-05-17
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-12-19
  • 2021-09-07
猜你喜欢
  • 2021-05-31
  • 2021-05-19
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-06-30
相关资源
相似解决方案