I have a 12k X 12k sparse array (~1% density) and I need to:
take the square root of all the elements
flip the sign of all the elements in the top-left half of the matrix
For example, say that the matrix looks like:
$\begin{bmatrix}a&b&c\\d&e&f\\g&h&i \end{bmatrix}$
the output should read:
$\begin{bmatrix}-\sqrt{a}&-\sqrt{b}&\sqrt{c}\\-\sqrt{d}&\sqrt{e}&\sqrt{f}\\\sqrt{g}&\sqrt{h}&\sqrt{i} \end{bmatrix}$
For a small matrix, I would create a "mask" and multiply it to the sqare root of the matrix, as in the example below for a 10x10 random matrix:
negMask =
Join[ConstantArray[-1, 10 - #], ConstantArray[1, #]] & /@ Range[10];
negMask*Sqrt[RandomInteger[2, {10, 10}]]
However, this is too slow for a 12k X 12k matrix, and doesn't exploit the sparsity of the matrix I need to process (and intuitively I'd say that it should be possible to use the sparsity to speed up the computation).
Any suggestion on how to process the matrix quickly?
