#sparse
from scipy import sparse as sp
from numpy import array,r_
I = array([0,0,1,3,1,0,0])
J = array([0,2,1,3,1,0,0])
V = array([1,1,1,1,1,1,2])
# zde se opakovane indexy poscitaji
B = sp.coo_matrix((V,(I,J)),shape=(4,4)).tocsr()
B.todense()
#zde se prepisi
A = sp.coo_matrix((V,(I,J)),shape=(4,4)).todia()
(A-B).todense()
from scipy import io
io.mmwrite("resmat",B,precision=5)
!head resmat.mtx
C=sp.coo_matrix((V*(1.2+.2j),(I,J)),shape=(4,4)).tocsr()
io.mmwrite("resmat2",C,precision=5)
!head resmat2.mtx