在 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与自身相乘则正常运行。
tf.sparse_matmul
?它有何不同之处? - mrgloom