【发布时间】:2016-03-05 22:48:42
【问题描述】:
稀疏张量与它们自身或与密集张量的乘法似乎在 TensorFlow 中不起作用。下面的例子
from __future__ import print_function
import tensorflow as tf
x = tf.constant([[1.0,2.0],
[3.0,4.0]])
y = tf.SparseTensor(indices=[[0,0],[1,1]], values=[1.0,1.0], shape=[2,2])
z = tf.matmul(x,y)
sess = tf.Session()
sess.run(tf.initialize_all_variables())
print(sess.run([x, y, z]))
失败并显示错误消息
TypeError: Input 'b' of 'MatMul' Op has type string that does not match type
float32 of argument 'a'
两个张量都有 float32 类型的值,通过在没有乘法运算的情况下评估它们可以看出。 y 与自身相乘会返回类似的错误消息。 x 与自身相乘可以正常工作。
【问题讨论】: