-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixPlotter.py
executable file
·48 lines (36 loc) · 1.24 KB
/
matrixPlotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
import sys
import pylab
from scipy.io.mmio import mmread, mminfo
from scipy.sparse import coo_matrix
def main():
if (len(sys.argv) != 2):
print "Usage: " + sys.argv[0] + " matrix-name"
sys.exit(0)
# end if
matrixName=sys.argv[1]+ ".mtx"
mm = open(sys.argv[1]+'.mm', 'w')
outputName=sys.argv[1]+ ".png"
#outputName=sys.argv[1]+ ".pdf"
(n,n,nz,void,fld,symm) = mminfo(matrixName)
A = mmread(matrixName).tocsr().tocoo()
# creating a file in coo format
#print n, n, A.size
mm.write( str(n) + ' ' + str(n) + ' ' + str(A.size) + '\n')
for i in range(A.size):
mm.write( str(A.row[i])+ ' ' + str(A.col[i])+ ' ' + str(A.data[i])+ '\n')
#print A.row[i]+1, A.col[i]+1 , A.data[i]
# end for
#print repr(A)
#print A.col
#print A.size
# end of creating a file in coo format
#pylab.title("Matrix :" + matrixName, fontsize=22)
pylab.title("Matrix: " + sys.argv[1] + ", n:" + str(n) + ", nz:" + str(A.size) + '\n',fontsize=10 )
pylab.spy(A,marker='.',markersize=1)
pylab.savefig(outputName,format=None)
#pylab.show()
# end of main()
if __name__ == '__main__':
main()
# end if