Skip to content

Instantly share code, notes, and snippets.

@vighneshbirodkar
Created May 19, 2014 17:28
Show Gist options
  • Save vighneshbirodkar/a2ef1314a60de6a0e4e5 to your computer and use it in GitHub Desktop.
Save vighneshbirodkar/a2ef1314a60de6a0e4e5 to your computer and use it in GitHub Desktop.
scipy csr_matrix demo
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