-->

Friday, March 22, 2013

sparse matrices from matlab to python


#Load your matlab matrix in python
testFree=scipy.io.loadmat('TestFreeSparse.mat')

#get the matrix
Test=testFree['TestSparse']

#to dense
TestDense=Test.todense()

# get the indexes of non-zero values
I,J= Test.nonzero()


# get the data
V=Test.data

G = scipy.sparse.csr_matrix((V,(I,J)))
G[0,112342]

No comments:

Post a Comment