zephyrus
zephyrus

Reputation: 1266

set diagonal values of tensor to 0

It seems that there is no simple way to assign a value to the diagonal of a Tensor. Ideally I am looking for a command like numpy.fill_diagonal.

Currently I accomplish this by doing:

tf.matrix_set_diag(
                matrix,
                tf.zeros_like(matrix.shape[0:-1]),
                name=None
            )

Is there a better way?

Upvotes: 5

Views: 3166

Answers (2)

jubueche
jubueche

Reputation: 793

This should be updated to tf.linalg.set_diag, which can be found here

Upvotes: 1

tianchi
tianchi

Reputation: 21

I think your answer should be:

tf.matrix_set_diag(matrix, tf.zeros(matrix.shape[0:-1]), name=None)

Upvotes: 2

Related Questions