For some problems (e.g. PDOS calculation) I would like to have/implement something like SparseData, that is like ArrayData but stores on disk a sparse-matrix representation of numpy array.
Small snippet of how it can be done with existing scipy.sparse library:
#+begin_src python :results output
import numpy as np
from scipy.sparse import csr_matrix
bands = [[0, 0, 0, 58.2, 93.6, 0],
[0, 0, 113.7, 33.5, 0, 0],
[0, 205, 0, 506, 0, 0]]
# indptr = [0, 2, 4, 6]
# indices = [3, 4, 2, 3, 1, 3]
# data = [58, 93, 113, 33, 205, 506]
indptr = [0]
indices = []
data = []
for b in bands:
for pos, num in enumerate(b):
if (num != 0.):
indices.append(pos)
data.append(num)
indptr.append(len(data))
print csr_matrix((data, indices, indptr), dtype=float).toarray()
#+end_src
#+RESULTS:
: [[ 0. 0. 0. 58.2 93.6]
: [ 0. 0. 113.7 33.5 0. ]
: [ 0. 205. 0. 506. 0. ]]
For some problems (e.g. PDOS calculation) I would like to have/implement something like
SparseData
, that is likeArrayData
but stores on disk a sparse-matrix representation of numpy array.Small snippet of how it can be done with existing
scipy.sparse
library: