【问题标题】:How can I perform Sparse Matrix * Sparse Matrix Multiplication in TensorFlow?如何在 TensorFlow 中执行稀疏矩阵 * 稀疏矩阵乘法?
【发布时间】:2018-08-14 11:41:05
【问题描述】:

目前我正在尝试使用 TensorFlow 计算矩阵乘法,其中两个矩阵都是稀疏形式。我尝试使用tf.sparse_matmul(),但在这种情况下,我不得不转换回密集形式,这破坏了我的项目目标。请建议我在这种情况下我能做什么。

【问题讨论】:

标签: python tensorflow matrix


【解决方案1】:

你试过tf.sparse_matmul吗?

 sparse_matumul_result = tf.sparse_matmul(a, b)

如果你也需要sparse_matmul_result 作为稀疏,你可以这样做:

 tf.contrib.layers.dense_to_sparse(sparse_matmul_result)

【讨论】:

  • 根据文档,这两个矩阵都必须是张量而不是稀疏张量。但在我的情况下,这两个矩阵都是 SparseTensors。恐怕,使用 tf.sparse_matmul() 我需要将 SparseTensors 转换为密集张量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-21
  • 1970-01-01
  • 1970-01-01
  • 2017-07-20
  • 2011-11-20
  • 2017-12-03
相关资源
最近更新 更多