Function name for setting all nonzeros to 1

35 Views Asked by At

For the purposes of a naming convention,

what is the name for the mathamatical function that, given a sparse matrix $M$, sets all non-zero values in $M$ to 1, and leaves the matrix otherwise unchanged?

It's like the indicator function, or the Kronecker delta (except instead of an equality, it is a 1 if not equal to j, 0 otherwise--where j is 0)...

But I don't remember what it is called

1

There are 1 best solutions below

1
On BEST ANSWER

You could do $x=|\operatorname{sgn}(x)|,$ the signum function, defined by $$\operatorname{sgn}(x)=\begin{cases}1,&x>0\\ 0, &x=0\\-1,&x<0\end{cases}.$$ Warning, though: if you're doing this numerically, testing for a double number equal to zero has issues. Probably best to test if a number is within machine epsilon of zero.