Skip to content
Advertisement

Exponential of SparseTensor with mapping

I want to take the exp of each element in the sparse matrix. Here is a simple example:

JavaScript

But this gives the followig error:

JavaScript

Can you please help me to sort this out without converting this to dense matrix?

Advertisement

Answer

If you have Tensorflow 2.4, you can use tf.sparse.map_values:

JavaScript

Here is the magic:

JavaScript
JavaScript

Note that tf.sparse.to_dense is only there so we can visualize the result. Also, I had to convert your values to floating point.

Advertisement