Minimal example for tf.raw_ops.DenseToCSRSparseMatrix

Would you please give me a simple example to work with tf.raw_ops.DenseToCSRSparseMatrix. Here is my latest try but It didn’t work:

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

ss = tf.constant([[1, 2, 3, 4, 5], [0, 0, 0, 2, 1]], dtype=tf.float32)
indecies = tf.where(tf.not_equal(ss, 0))

b = tf.compat.v1.raw_ops.DenseToCSRSparseMatrix(dense_input=ss, indices=indecies)


with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(b))

I think this is deprecated.

Have you already checked:

https://www.tensorflow.org/api_docs/python/tf/sparse/from_dense

And more in general the sparse tensor guide

Thanks for your reply. tf.sparse only supports the COO format. However, I need the CSR format.

If you need CSR you can take a look to this tests: