As a MATLAB user for many years, I am now switching to python.
I am trying to find a brief way to simply rewrite the following MATLAB code in python:
s = sum(Mtx);
newMtx = Mtx(:, s>0);
where Mtx is a two-dimensional sparse matrix
My python solution:
s = Mtx.sum(0)
newMtx = Mtx[:, np.where((s>0).flat)[0]]
where Mtx is the sparse 2D CSC matrix
The python code is not as readable / elegant as in matlab .. any idea how to write it more elegantly?
Thank!
yuval source
share