我有两个矩阵,F(shape = (4000,64))和M(shape=(4000,9)),并希望得到形状= (4000,64*9)的结果。
我可以用下面的代码来思考for循环(理想)
result = np.zeros(4000,64*9)
ind = 0
for i in range(64):
for j in range(9):
result[:,ind]= tf.muliply(F[:,i]),M[:,j])
ind += 1但我知道循环不支持tensorflow
是否有执行上述代码相同功能的函数?
编辑)
我想出了个主意。F,m重复形状(4000,64*9)立克爬行动物在MATLAB和元素乘。你还能有别的想法吗?
发布于 2017-07-08 08:45:17
你可以用
tf.reshape(M[:,tf.newaxis,:] * F[...,tf.newaxis], [4000,-1])发布于 2017-07-08 07:43:33
如果您对tf.matmul和M(shape=(4000,1, 9))的输入进行了整形,则可以使用M(shape=(4000,1, 9))。举个例子
F = tf.Variable(tf.random_uniform(shape=(4000, 64, 1)))
M = tf.Variable(tf.random_uniform(shape=(4000, 1, 9)))
C = tf.matmul(F, M)
C = tf.reshape(C, (4000, -1))
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
print(C.eval().shape)
#Output: (4000, 576)https://stackoverflow.com/questions/44983465
复制相似问题