A = tf.placeholder(tf.float32, [None,10])
B = tf.Variable(tf.random_normal([10,20]))
C = tf.matmul(A, B)
D = tf.matmul(tf.transpose(C), A) # the value of A.shape[0]
1 回答
1
您已经将张量 A 的值传递给占位符,当您这样做时,您已经知道它的形状 . 我会为你关心的形状创建另一个占位符并传递它:
import tensorflow as tf
import numpy as np
A = tf.placeholder(tf.float32, [None,10])
L = tf.placeholder(tf.float32, None)
B = tf.Variable(tf.random_normal([10,20]))
C = tf.matmul(A, B)
D = tf.multiply(tf.transpose(C), L) // L is a number, matmul does not multiply matrix with a number
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
a = np.zeros((5, 10), dtype=np.float32)
l = a.shape[0]
sess.run(D, {A: a, L: l})
1 回答
您已经将张量
A
的值传递给占位符,当您这样做时,您已经知道它的形状 . 我会为你关心的形状创建另一个占位符并传递它: