Skip to content
Snippets Groups Projects

Block Compressed Row Storage Format

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Ben Stolle
    Edited
    bsr_scipy.py 965 B
    # %%
    import numpy as np
    from scipy import sparse
    # https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.bsr_array.html#scipy.sparse.bsr_array
    
    # %%
    A = np.array([[1., 0., 0., 0., 0., 0., 0., 0.],
    ...        [3., 5., 0., 0., 0., 0., 0., 0.],
    ...        [0., 0., 0., 1., 0., 0., 0., 0.],
    ...        [0., 0., 2., 0., 0., 0., 0., 0.],
    ...        [0., 0., 5., 2., 0., 1., 0., 0.],
    ...        [2., 0., 0., 0., 0., 0., 0., 0.],
    ...        [0., 0., 0., 4., 0., 0., 3., 1.],
    ...        [0., 0., 0., 5., 0., 0., 0., 2.]])
    
    # %%
    m = sparse.bsr_array(A, blocksize=(4,4))
    
    # %%
    m.data # corresponding block values are stored in data[ indptr[i]: indptr[i+1] ]
    
    # %%
    # column index, different to paper
    m.indices #  block column indices for row i are stored in indices[indptr[i]:indptr[i+1]]
    
    # %%
    # row pointer
    m.indptr # BSR format index pointer array
    
    # %%
    #m2by2 = sparse.bsr_array(A, blocksize=(2,2))
    #print(m2by2.data)
    #print(m2by2.indices)
    #print(m2by2.indptr)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment