In [16]:
from scipy import sparse
import numpy as np
In [19]:
IA = np.array([1,2,3,1,4,0,4,2])
JA = np.array([1,3,4,2,5,0,4,1])
V =  np.array([1,2,5,2,4,7,6,2], dtype=float)

A = sparse.coo_matrix((V,(IA,JA)),shape=(5,6))
In [8]:
print(A)
  (1, 1)	1.0
  (2, 3)	2.0
  (3, 4)	5.0
  (1, 2)	2.0
  (4, 5)	4.0
  (0, 0)	7.0
  (4, 4)	6.0
  (2, 1)	2.0
In [9]:
print(A.todense())
[[ 7.  0.  0.  0.  0.  0.]
 [ 0.  1.  2.  0.  0.  0.]
 [ 0.  2.  0.  2.  0.  0.]
 [ 0.  0.  0.  0.  5.  0.]
 [ 0.  0.  0.  0.  6.  4.]]
In [10]:
print(A.nnz)
8
In [14]:
print(A.data.nbytes)
print(A.row.nbytes)
print(A.col.nbytes)
64
32
32
In [ ]: