In [2]:
import scipy.sparse as sp
import pyamg
%matplotlib inline
In [3]:
A = pyamg.gallery.sprand(10,10,30.0/100)
In [5]:
A = A.tocsr()
print(A.data.shape)
print(A.indices.shape)
print(A.indptr.shape)
print(A.data.nbytes)
print(A.indices.nbytes)
print(A.indptr.nbytes)
(25,)
(25,)
(11,)
200
100
44
In [6]:
A = A.tocoo()
print(A.data.nbytes)
print(A.row.nbytes)
print(A.col.nbytes)
200
100
100
In [7]:
print(A.nnz)
A = A.todia()
print(A.nnz)
print(A.offsets)
print(A.data.nbytes)
print(A.offsets.nbytes)
print(A.data)
25
74
[-7 -6 -5 -4 -3 -2  0  1  3  4  5  7  9]
1040
52
[[ 0.          0.03063993  0.          0.          0.          0.          0.
   0.          0.          0.        ]
 [ 0.75051826  0.          0.          0.          0.          0.          0.
   0.          0.          0.        ]
 [ 0.          0.7576617   0.          0.          0.          0.          0.
   0.          0.          0.        ]
 [ 0.17079835  0.          0.          0.61705619  0.          0.          0.
   0.          0.          0.        ]
 [ 0.          0.          0.          0.          0.7028737   0.
   0.52948607  0.          0.          0.        ]
 [ 0.          0.          0.          0.50467309  0.          0.          0.
   0.          0.          0.        ]
 [ 0.          0.          0.          0.          0.18618383  0.          0.
   0.6120013   0.73886266  0.59266088]
 [ 0.          0.          0.35770397  0.55841525  0.          0.          0.
   0.36958883  0.          0.68733541]
 [ 0.          0.          0.          0.          0.          0.          0.
   0.20377868  0.          0.32896987]
 [ 0.          0.          0.          0.          0.85892431  0.
   0.52630535  0.          0.68856167  0.15359835]
 [ 0.          0.          0.          0.          0.          0.          0.
   0.40646688  0.          0.        ]
 [ 0.          0.          0.          0.          0.          0.          0.
   0.97353235  0.          0.        ]
 [ 0.          0.          0.          0.          0.          0.          0.
   0.          0.          0.79371039]]
In [4]:
plt.spy(A, marker='.', markersize=5)
Out[4]:
<matplotlib.lines.Line2D at 0x104eead90>
In [ ]: