【问题标题】:How to do elementwise multiplication between a sparse and a dense tensors in tensorflow?如何在张量流中的稀疏和密集张量之间进行元素乘法?
【发布时间】:2017-08-02 17:49:41
【问题描述】:

Tensorflow 实现了tf.sparse_tensor_dense_matmul 的稀疏到稠密矩阵乘法,但是它是否具有稀疏到稠密的元素乘法(两个张量具有相同的形状)?我想避免将我的稀疏张量转换为密集张量,因为它不适合内存。

【问题讨论】:

    标签: python tensorflow sparse-matrix


    【解决方案1】:

    我不相信有内置功能,但你可以相对容易地手动完成,至少如果你不打算支持广播的话。如果xy 分别是。你的稀疏和密集张量,

    res = tf.SparseTensor(x.indices, tf.gather_nd(y, x.indices) * x.values, x.dense_shape)
    

    您可能还想在相乘之前检查yx 的形状是否相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      相关资源
      最近更新 更多