Matlab Question on Sparse Matrices

I have a sparse matrix S. I perform the following operation D1 = diag(sum(S,2)), basically forming a diagonal matrix. Now I need to execute (D1)^(-0.5), but I get the error "Error using mpower, use full (x) ^ full (y)"

Converting to full power will defeat the purpose of using a sparse matrix.

Any advice would be very helpful.

+3
source share
1 answer

Bringing the diagonal matrix to power can be done simply by performing the operation on the diagonal elements elemental ... like this:

D1_diagonal_elements = sum(S,2);
your_result = diag(D1_diagonal_elements .^ (-0.5));
+3
source

Source: https://habr.com/ru/post/1796619/


All Articles