Hi I am tryigng to do a 3D SparseTensor matrix multiplication with 2D Tensor. Here is a toy example:
3D tensor matrix multiplication with 2D Tensor
import tensorflow as tf
import numpy as np
a = np.array([[[1., 0., 2., 0.],
[3., 0., 0., 4.]]])
b = (np.array([1., 2.])[:,np.newaxis]).T
a_t = tf.constant(a)
b_t = tf.constant(b)
tf.matmul(b_t,a_t)
<tf.Tensor: shape=(1, 1, 4), dtype=float64, numpy=array([[[7., 0., 2., 8.]]])>
3D SparseTensor matrix multiplication with 2D Tensor
import tensorflow as tf
import numpy as np
a = np.array([[[1., 0., 2., 0.],
[3., 0., 0., 4.]]])
b = (np.array([1., 2.])[:,np.newaxis]).T
a_t = tf.constant(a)
b_t = tf.constant(b)
a_s = tf.sparse.from_dense(a_t)
tf.sparse.sparse_dense_matmul(b_t,a_s)
InvalidArgumentError: Tensor 'a_shape' must have 2 elements [Op:SparseTensorDenseMatMul]
Can you please help me to sort out this error?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…