scipy.sparse.dia_matrix

class scipy.sparse.dia_matrix(arg1, shape=None, dtype=None, copy=False)

Sparse matrix with DIAgonal storage

This can be instantiated in several ways:
dia_matrix(D)
with a dense matrix
dia_matrix(S)
with another sparse matrix S (equivalent to S.todia())
dia_matrix((M, N), [dtype])
to construct an empty matrix with shape (M, N), dtype is optional, defaulting to dtype=’d’.
dia_matrix((data, offsets), shape=(M, N))
where the data[k,:] stores the diagonal entries for diagonal offsets[k] (See example below)

Notes

Sparse matrices can be used in arithmetic operations: they support addition, subtraction, multiplication, division, and matrix power.

Examples

>>> from scipy.sparse import *
>>> from scipy import *
>>> dia_matrix( (3,4), dtype=int8).todense()
matrix([[0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0]], dtype=int8)
>>> data = array([[1,2,3,4]]).repeat(3,axis=0)
>>> offsets = array([0,-1,2])
>>> dia_matrix( (data,offsets), shape=(4,4)).todense()
matrix([[1, 0, 3, 0],
        [1, 2, 0, 4],
        [0, 2, 3, 0],
        [0, 0, 3, 4]])

Attributes

dtype
shape
ndim
nnz
data DIA format data array of the matrix
offsets DIA format offset array of the matrix

Methods

asformat
asfptype
astype
conj
conjugate
copy
diagonal
dot
getH
get_shape
getcol
getformat
getmaxprint
getnnz
getrow
mean
multiply
nonzero
reshape
set_shape
setdiag
sum
toarray
tobsr
tocoo
tocsc
tocsr
todense
todia
todok
tolil
transpose

This Page