scipy.sparse.dia_matrix

class scipy.sparse.dia_matrix(arg1, shape=None, dtype=None, copy=False)[源代码]

具有对角存储的稀疏矩阵

这可以通过几种方式实例化:
直径矩阵(D)

具有密集的矩阵

直径矩阵(S)

具有另一个稀疏矩阵S(等价于S.todia())

直径矩阵((M,N), [数据类型] )

要构造形状为(M,N)的空矩阵,dtype是可选的,默认为dtype=‘d’。

DIA_MATRIX((数据,偏移),形状=(M,N))

其中 data[k,:] 存储对角线的对角线条目 offsets[k] (请参见下面的示例)

注意事项

稀疏矩阵可用于算术运算:它们支持加、减、乘、除和矩阵幂。

示例

>>> import numpy as np
>>> from scipy.sparse import dia_matrix
>>> dia_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]], dtype=int8)
>>> data = np.array([[1, 2, 3, 4]]).repeat(3, axis=0)
>>> offsets = np.array([0, -1, 2])
>>> dia_matrix((data, offsets), shape=(4, 4)).toarray()
array([[1, 0, 3, 0],
       [1, 2, 0, 4],
       [0, 2, 3, 0],
       [0, 0, 3, 4]])
>>> from scipy.sparse import dia_matrix
>>> n = 10
>>> ex = np.ones(n)
>>> data = np.array([ex, 2 * ex, ex])
>>> offsets = np.array([-1, 0, 1])
>>> dia_matrix((data, offsets), shape=(n, n)).toarray()
array([[2., 1., 0., ..., 0., 0., 0.],
       [1., 2., 1., ..., 0., 0., 0.],
       [0., 1., 2., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 2., 1., 0.],
       [0., 0., 0., ..., 1., 2., 1.],
       [0., 0., 0., ..., 0., 1., 2.]])
属性
dtype数据类型

矩阵的数据类型

shape2元组

获得矩阵的形状。

ndim集成

维数(该值始终为2)

nnz

存储值的数量,包括显式零。

data

DIA格式的矩阵数据数组

offsets

DIA格式矩阵的偏移量数组

方法:

__len__ \()

__mul__ \(其他)

解释其他并调用以下任一

arcsin \()

基于元素的反正弦。

arcsinh \()

以元素为单位的反正弦。

arctan \()

基于元素的弧线。

arctanh \()

以元素为单位的弧度。

asformat \(格式[, copy] )

以传递的格式返回此矩阵。

asfptype \()

将矩阵向上转换为浮点格式(如有必要)

astype \(dtype[, casting, copy] )

将矩阵元素强制转换为指定类型。

ceil \()

按元素排列的单元格。

conj \([copy] )

元素复数共轭。

conjugate \([copy] )

元素复数共轭。

copy \()

返回此矩阵的副本。

count_nonzero \()

非零条目数,相当于

deg2rad \()

元素方向的de2rad。

diagonal \([k] )

返回矩阵的第k条对角线。

dot \(其他)

普通点积

expm1 \()

基于元素的表达式1。

floor \()

基于图元的楼板。

getH \()

返回此矩阵的厄米转置。

get_shape \()

获得矩阵的形状。

getcol \(J)

以(M X 1)稀疏矩阵(列向量)的形式返回矩阵第j列的副本。

getformat \()

矩阵表示形式为字符串的格式。

getmaxprint \()

打印时显示的最大元素数。

getnnz \([axis] )

存储值的数量,包括显式零。

getrow \(i)

以(1 X N)稀疏矩阵(行向量)的形式返回矩阵第i行的副本。

log1p \()

基于元素的log1p。

maximum \(其他)

此矩阵与另一个矩阵之间的元素最大值。

mean \([axis, dtype, out] )

计算沿指定轴的算术平均值。

minimum \(其他)

此矩阵与另一个矩阵之间的元素最小值。

multiply \(其他)

另一个矩阵的逐点乘法

nonzero \()

非零折射率

power \(n[, dtype] )

此函数执行元素级电源。

rad2deg \()

基于元素的rad2deg。

reshape \(自身,形状[, order, copy] )

在不更改稀疏矩阵数据的情况下为其赋予新形状。

resize \(*形状)

就地调整矩阵大小至给定的尺寸 shape

rint \()

基于元素的Rint。

set_shape \(形状)

看见 reshape

setdiag \(值[, k] )

设置阵列的对角或非对角元素。

sign \()

以元素为基础的符号。

sin \()

基于元素的罪过。

sinh \()

基于元素的SINH。

sqrt \()

基于元素的sqrt。

sum \([axis, dtype, out] )

对给定轴上的矩阵元素求和。

tan \()

按元素晒黑。

tanh \()

基于元素的TANH。

toarray \([order, out] )

返回此矩阵的密集ndarray表示。

tobsr \([blocksize, copy] )

将此矩阵转换为挡路稀疏行格式。

tocoo \([copy] )

将此矩阵转换为坐标格式。

tocsc \([copy] )

将此矩阵转换为压缩的稀疏列格式。

tocsr \([copy] )

将此矩阵转换为压缩的稀疏行格式。

todense \([order, out] )

返回此矩阵的密集矩阵表示形式。

todia \([copy] )

将此矩阵转换为稀疏对角线格式。

todok \([copy] )

将此矩阵转换为键字典格式。

tolil \([copy] )

将此矩阵转换为列表列表格式。

trace \([offset] )

返回稀疏矩阵沿对角线的总和。

transpose \([axes, copy] )

反转稀疏矩阵的维数。

trunc \()

基于元素的主干。