1. 程式人生 > >tf.shape和tf.less

tf.shape和tf.less

tf.shape返回張量的形狀

tf.less返回兩個張量各元素比較(x<y)得到的真假值組成的張量

import tensorflow as tf
A=[[1,2,3]]
t = tf.shape(A)
i=[3,2]
r = tf.less(i, t)
with tf.Session() as sess:
    print(sess.run(t))
    print(sess.run(r))

結果:

[1 3]
[False  True]

import tensorflow as tf
A=[[1,2,3],
   [4,5,6]]
t = tf.shape(A)
i=[[1,2,3],
   [1,2,3]]
r = tf.less(i, A)
with tf.Session() as sess:
    print(sess.run(t))
    print(sess.run(r))

結果:

[2 3]
[[False False False]
 [ True  True  True]]