-
Notifications
You must be signed in to change notification settings - Fork 75.3k
Closed
Labels
type:docs-bugDocument issuesDocument issues
Description
TensorFlow behaves differently (and surprisingly) to SciPy when converting sparse matrices to dense matrices.
import tensorflow as tf
import scipy as sp
import scipy.sparse
i = [0, 0]
j = [0, 0]
values = [1, 2]
sp_answer = sp.sparse.coo_matrix((values, (i, j))).todense()
print("SciPy's answer is " + str(sp_answer)) # prints [[3]]
tf_answer = tf.sparse_to_dense([i, j], [1, 1], values, 0)
print("TF's answer is " + str(tf.Session().run(tf_answer))) # prints [[2]]Specifically, if an index pair is repeated, then SciPy will sum the corresponding values, while TF just keeps the last value.
Is this behaviour intentional or accidental? If it's intentional, I'll make a pull request to add a mention of it to the docs. If it's accidental, I'll make a pull request to fix it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type:docs-bugDocument issuesDocument issues