<div>It seems that numpy universal functions only apply to ndarray (or dense matrix). Is there a way to apply them to scipy sparse matrices also?</div><div><br></div><div>For example, suppose S is an large sparse matrix (lil_matrix format, dtype=np.float). I want to get another sparse matrix B (of the same shape) that represents the signs of corresponding entries of S.</div>

<div><br></div><div>I wrote down "B=np.sign(S)" first, but it did not give me the desired output. I realized that np.sign() might not work for a sparse matrix, so I have to convert S to a dense matrix, i.e.</div>

<div><br></div><div>B = np.sign( S.todense() )</div><div><br></div><div>However, converting a large sparse matrix to dense would easily eat up the memory. Is there a way for np.sign (as well as other ufunc) to take a sparse matrix as parameter, and return a sparse matrix?</div>

<div><br></div><div>(If I recall correctly, in Matlab all functions work on both dense matrices and sparse matrices.)</div><br clear="all">--<div>Pengkui</div><br>