0
我想檢查兩個張量是否具有相同的形狀。檢查兩個張量形狀是否相同,包括無的最佳方法是什麼?
假設我有一些張量是這樣的:
a = tf.placeholder(tf.float32, shape=[None, 3])
b = tf.placeholder(tf.float32, shape=[None, 3])
我加assert a.shape == b.shape
。但是,這可能是由於無。的確,a.shape
= (?, 1)
,以及b.shape
是(?, 1)
。他們看起來和我一樣。
如果沒有無,它工作正常。
a = tf.placeholder(tf.float32, shape=[1, 3])
b = tf.placeholder(tf.float32, shape=[1, 3])
assert a.shape == b.shape # True
如何在形狀檢查中忽略無?
總結:
1: a = tf.placeholder(tf.float32, shape=[1, 3])
2: b = tf.placeholder(tf.float32, shape=[1, 3])
3: assert a.shape == b.shape # True
4:
5: a = tf.placeholder(tf.float32, shape=[None, 3])
6: b = tf.placeholder(tf.float32, shape=[None, 3])
7: assert a.shape == b.shape # False
我想在第7行的說法是真實的。
謝謝!如果我們有像tf.TensorShape.assert_same()這樣的東西,那就太好了。 –