Created
May 19, 2014 17:28
-
-
Save vighneshbirodkar/a2ef1314a60de6a0e4e5 to your computer and use it in GitHub Desktop.
scipy csr_matrix demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.sparse import * | |
import pygraphviz as pgv | |
import random | |
a = np.array([[1,0,0,0], | |
[5,2,0,0], | |
[1,7,2,0], | |
[0,0,0,4]]) | |
a = csr_matrix(a) | |
a.data[1] = 0 | |
print a.data | |
print a.indices | |
# Deleting a row is not possible without re arranging the the rest of indptr | |
# array | |
print a.indptr | |
# now the 2nd row contains a 0 entry | |
print a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment