spd_learn.functional.off_diag#
- spd_learn.functional.off_diag(X: Tensor) Tensor[source]#
Extract the hollow off-diagonal part of a matrix (zeroing the diagonal).
Given a square matrix \(X\), this returns:
\[\text{off\_diag}(X) = X - \text{diag}(\text{diag}(X))\]preserving the shape and off-diagonal entries while setting all diagonal elements to zero.
- Parameters:
X (torch.Tensor) – Input tensor of shape (…, n, n).
- Returns:
Hollow matrix with zero diagonal, shape (…, n, n).
- Return type:
Examples
>>> import torch >>> from spd_learn.functional import off_diag >>> X = torch.ones(3, 3) >>> off_diag(X) tensor([[0., 1., 1.], [1., 0., 1.], [1., 1., 0.]])