SciPy-1-12-中文文档-三十五-

91 阅读52分钟

SciPy 1.12 中文文档(三十五)

原文:docs.scipy.org/doc/scipy-1.12.0/index.html

scipy.sparse.bsr_array

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.bsr_array.html#scipy.sparse.bsr_array

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

块稀疏行格式稀疏数组。

可以通过几种方式实例化:

bsr_array(D, [blocksize=(R,C)])

其中 D 是一个二维数组。

bsr_array(S, [blocksize=(R,C)])

与另一个稀疏数组或矩阵 S 进行比较(等效于 S.tobsr())。

bsr_array((M, N), [blocksize=(R,C), dtype])

用于构建形状为(M, N)的空稀疏数组,数据类型是可选的,默认为 dtype='d'。

bsr_array((data, ij), [blocksize=(R,C), shape=(M, N)])

其中dataij满足a[ij[0, k], ij[1, k]] = data[k]

bsr_array((data, indices, indptr), [shape=(M, N)])

是标准的 BSR 表示,其中第 i 行的块列索引存储在indices[indptr[i]:indptr[i+1]]中,它们对应的块值存储在data[indptr[i]:indptr[i+1]]中。如果未提供 shape 参数,则从索引数组中推断数组的尺寸。

注意事项

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

BSR 格式摘要

块稀疏行(BSR)格式与压缩稀疏行(CSR)格式非常相似。对于具有稠密子矩阵的稀疏矩阵,例如下面的最后一个示例,BSR 格式非常适合。这种稀疏块矩阵经常出现在向量值有限元离散化中。在这种情况下,BSR 比 CSR 和 CSC 在许多稀疏算术操作中要高效得多。

块大小

块大小(R,C)必须均匀地划分稀疏数组的形状(M,N)。也就是说,R 和 C 必须满足关系M % R = 0N % C = 0

如果未指定块大小,则将应用简单的启发式方法来确定合适的块大小。

规范格式

在规范格式中,没有重复的块,并且索引按行排序。

示例

>>> import numpy as np
>>> from scipy.sparse import bsr_array
>>> bsr_array((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3 ,4, 5, 6])
>>> bsr_array((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
 [0, 0, 3],
 [4, 5, 6]]) 
>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6]).repeat(4).reshape(6, 2, 2)
>>> bsr_array((data,indices,indptr), shape=(6, 6)).toarray()
array([[1, 1, 0, 0, 2, 2],
 [1, 1, 0, 0, 2, 2],
 [0, 0, 0, 0, 3, 3],
 [0, 0, 0, 0, 3, 3],
 [4, 4, 5, 5, 6, 6],
 [4, 4, 5, 5, 6, 6]]) 

属性:

dtype数据类型

数组的数据类型

shape二元组

数组的形状。

ndim整数

维度的数量(始终为 2)

nnz

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

size

存储值的数量。

数据

BSR 格式数组的数据数组

indices

BSR 格式数组的索引数组

indptr

BSR 格式数组的索引指针数组

blocksize

矩阵的块大小。

has_sorted_indicesbool

Whether the indices are sorted

has_canonical_formatbool

Whether the array/matrix has sorted indices and no duplicates

T

转置。

Methods

__len__()
arcsin()逐元素的反正弦。
arcsinh()逐元素的反双曲正弦。
arctan()逐元素的反正切。
arctanh()逐元素的反双曲正切。
argmax([axis, out])返回沿轴的最大元素的索引。
argmin([axis, out])返回沿轴的最小元素的索引。
asformat(format[, copy])返回以指定格式表示的数组/矩阵。
asfptype()将数组/矩阵转换为浮点数格式(如有必要)。
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()逐元素的向上取整。
check_format([full_check])检查数组/矩阵是否符合 BSR 格式。
conj([copy])逐元素的复共轭。
conjugate([copy])逐元素的复共轭。
copy()返回该数组/矩阵的副本。
count_nonzero()非零条目的数量,等同于
deg2rad()元素级的 deg2rad。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通的点积。
eliminate_zeros()去除原地的零元素。
expm1()元素级的 expm1。
floor()元素级的 floor。
getH()返回该数组/矩阵的共轭转置。
get_shape()获取稀疏数组/矩阵的形状。
getcol(j)返回数组/矩阵的第 j 列的副本,作为 (m x 1) 稀疏数组/矩阵(列向量)。
getformat()稀疏数组/矩阵的存储格式。
getmaxprint()打印时显示的最大元素数量。
getnnz([axis])存储值的数量,包括显式的零值。
getrow(i)返回数组/矩阵的第 i 行的副本,作为 (1 x n) 稀疏数组/矩阵(行向量)。
log1p()元素级的 log1p。
max([axis, out])返回数组/矩阵或指定轴向的最大值。
maximum(other)该数组/矩阵与另一个数组/矩阵之间的元素级最大值。
mean([axis, dtype, out])计算沿指定轴的算术平均值。
min([axis, out])返回数组/矩阵或沿轴的最小值或最大值
minimum(other)与另一个数组/矩阵的逐元素最小值
multiply(other)与另一个数组/矩阵、向量或标量的逐点乘法
nanmax([axis, out])返回数组/矩阵或沿轴的最大值,忽略任何 NaN 值
nanmin([axis, out])返回数组/矩阵或沿轴的最小值,忽略任何 NaN 值
nonzero()数组/矩阵的非零索引
power(n[, dtype])逐元素的幂运算
prune()移除所有非零元素后的空间
rad2deg()逐元素的弧度转角度
reshape(self, shape[, order, copy])为稀疏数组/矩阵给出新的形状,不更改数据
resize(*shape)将数组/矩阵就地调整为给定的shape维度
rint()逐元素的四舍五入
set_shape(shape)参见reshape
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素
sign()逐元素的符号函数
sin()逐元素的正弦函数
sinh()逐元素的双曲正弦函数
sort_indices()对该数组/矩阵的索引进行排序,原地修改
sorted_indices()返回该数组/矩阵索引已排序的副本。
sqrt()逐元素的平方根函数。
sum([axis, dtype, out])沿给定轴对数组/矩阵元素求和。
sum_duplicates()通过将重复的数组/矩阵条目相加来消除重复项。
tan()逐元素的正切函数。
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()逐元素截断。
getitem
mul

scipy.sparse.coo_array

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.coo_array.html#scipy.sparse.coo_array

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

COO 格式的稀疏数组。

也称为‘ijv’或‘三元组’格式。

可以通过多种方式实例化:

coo_array(D)

其中 D 是一个二维 ndarray

coo_array(S)

使用另一个稀疏数组或矩阵 S(等同于 S.tocoo())

coo_array((M, N), [dtype])

构造一个形状为(M, N)的空数组,dtype 是可选的,默认为 dtype='d'。

coo_array((data, (i, j)), [shape=(M, N)])

通过三个数组构造:

  1. data[:] 数组条目,任意顺序

  2. i[:] 数组条目的行索引

  3. j[:] 数组条目的列索引

其中A[i[k], j[k]] = data[k]。当未指定形状时,将从索引数组中推断出形状

注意事项

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

COO 格式的优势

  • 有助于在稀疏格式之间快速转换

  • 允许重复条目(见示例)

  • 非常快速地转换为 CSR/CSC 格式

COO 格式的缺点

  • 不直接支持:

    • 算术运算

    • 切片

预期用法

  • COO 是一种快速构建稀疏数组的格式

  • 一旦构造了 COO 数组,可以转换为 CSR 或 CSC 格式进行快速算术和矩阵向量操作

  • 默认情况下,转换为 CSR 或 CSC 格式时,重复的(i, j)条目将被合并在一起。这有助于高效构建有限元矩阵等。(见示例)

规范格式

  • 条目和索引按行、然后列排序。

  • 没有重复条目(即没有重复的(i, j)位置)

  • 数据数组可能包含显式零值。

示例

>>> # Constructing an empty array
>>> import numpy as np
>>> from scipy.sparse import coo_array
>>> coo_array((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> # Constructing an array using ijv format
>>> row  = np.array([0, 3, 1, 0])
>>> col  = np.array([0, 3, 1, 2])
>>> data = np.array([4, 5, 7, 9])
>>> coo_array((data, (row, col)), shape=(4, 4)).toarray()
array([[4, 0, 9, 0],
 [0, 7, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 5]]) 
>>> # Constructing an array with duplicate indices
>>> row  = np.array([0, 0, 1, 3, 1, 0, 0])
>>> col  = np.array([0, 2, 1, 3, 1, 0, 0])
>>> data = np.array([1, 1, 1, 1, 1, 1, 1])
>>> coo = coo_array((data, (row, col)), shape=(4, 4))
>>> # Duplicate indices are maintained until implicitly or explicitly summed
>>> np.max(coo.data)
1
>>> coo.toarray()
array([[3, 0, 1, 0],
 [0, 2, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 1]]) 

属性:

数据类型dtype

数组的数据类型

shape2 元组

数组的形状。

维度整数

维度数量(始终为 2)

nnz

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

size

存储值的数量。

数据

数组的 COO 格式数据数组

COO 格式数组的行索引数组

数组的 COO 格式列索引数组

具有规范格式布尔值

矩阵是否具有排序索引且无重复

format

矩阵的格式字符串。

T

转置。

方法

__len__()
arcsin()逐元素的反正弦。
arcsinh()逐元素的反双曲正弦。
arctan()逐元素的反正切函数。
arctanh()逐元素的反双曲正切。
argmax([axis, out])返回沿轴的最大元素的索引。
argmin([axis, out])返回沿轴的最小元素的索引。
asformat(format[, copy])返回以指定格式的数组/矩阵。
asfptype()将数组/矩阵提升到浮点数格式(如有必要)。
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()逐元素的向上取整。
conj([copy])逐元素的复共轭。
conjugate([copy])逐元素的复共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零元素的数量,等同于
deg2rad()逐元素的角度转弧度。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通的点积。
eliminate_zeros()移除数组/矩阵中的零元素。
expm1()按元素计算 expm1。
floor()按元素向下取整。
getH()返回此数组/矩阵的共轭转置。
get_shape()获取稀疏数组/矩阵的形状。
getcol(j)返回数组/矩阵的第 j 列的副本,作为一个 (m x 1) 的稀疏数组/矩阵(列向量)。
getformat()稀疏数组/矩阵的存储格式。
getmaxprint()打印时显示的最大元素数量。
getnnz([axis])存储值的数量,包括显式的零。
getrow(i)返回数组/矩阵的第 i 行的副本,作为一个 (1 x n) 的稀疏数组/矩阵(行向量)。
log1p()按元素计算 log1p。
max([axis, out])返回数组/矩阵的最大值或沿轴的最大值。
maximum(other)在此数组/矩阵与另一个数组/矩阵之间按元素取最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
min([axis, out])返回数组/矩阵的最小值或沿轴的最小值。
minimum(other)在此数组/矩阵与另一个数组/矩阵之间按元素取最小值。
multiply(other)与另一个数组/矩阵的逐点乘积。
nanmax([axis, out])返回数组/矩阵的最大值或沿轴的最大值,忽略任何 NaN。
nanmin([axis, out])返回数组/矩阵的最小值,忽略 NaN 值。可以沿着某个轴计算最小值。
nonzero()返回数组/矩阵中非零元素的索引。
power(n[, dtype])对数组元素进行逐元素求幂运算。
rad2deg()逐元素将弧度转换为角度。
reshape(self, shape[, order, copy])在不改变数据的情况下为稀疏数组/矩阵赋予新的形状。
resize(*shape)将数组/矩阵原地调整为给定shape的维度。
rint()逐元素四舍五入。
set_shape(shape)参见 reshape
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()逐元素的符号函数。
sin()逐元素的正弦函数。
sinh()逐元素的双曲正弦函数。
sqrt()逐元素的平方根函数。
sum([axis, dtype, out])沿着给定轴对数组/矩阵元素进行求和。
sum_duplicates()通过将重复条目相加来消除重复条目。
tan()逐元素的正切函数。
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()逐元素截断。
mul

scipy.sparse.csc_array

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.csc_array.html#scipy.sparse.csc_array

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

压缩稀疏列数组。

可以通过几种方式实例化:

csc_array(D)

其中 D 是一个 2-D ndarray

csc_array(S)

with another sparse array or matrix S (equivalent to S.tocsc())

csc_array((M, N), [dtype])

以形状 (M, N) 构造一个空数组,dtype 是可选的,默认为 dtype='d'。

csc_array((data, (row_ind, col_ind)), [shape=(M, N)])

其中 datarow_indcol_ind 满足关系 a[row_ind[k], col_ind[k]] = data[k]

csc_array((data, indices, indptr), [shape=(M, N)])

标准的 CSC 表示,其中列 i 的行索引存储在 indices[indptr[i]:indptr[i+1]] 中,相应的值存储在 data[indptr[i]:indptr[i+1]] 中。如果未提供形状参数,则从索引数组中推断数组的维度。

注意事项

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

CSC 格式的优点

  • 高效的算术运算 CSC + CSC、CSC * CSC 等。

  • 高效的列切片

  • 快速矩阵向量乘积(CSR、BSR 可能更快)

CSC 格式的缺点

  • slow row slicing operations (consider CSR)

  • 更改稀疏结构的代价昂贵(考虑 LIL 或 DOK)

规范格式

  • 在每列中,索引按行排序。

  • 没有重复条目。

示例

>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> csc_array((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> row = np.array([0, 2, 2, 0, 1, 2])
>>> col = np.array([0, 0, 1, 2, 2, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csc_array((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 4],
 [0, 0, 5],
 [2, 3, 6]]) 
>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csc_array((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 4],
 [0, 0, 5],
 [2, 3, 6]]) 

属性:

dtypedtype

数组的数据类型

shape2-元组

数组的形状。

ndimint

维度数(始终为 2)

nnz

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

size

存储值的数量。

data

数组的 CSC 格式数据数组

indices

CSC 格式的索引数组

indptr

CSC 格式的索引指针数组

has_sorted_indices

索引是否已排序

has_canonical_format

数组/矩阵是否具有排序的索引且没有重复

T

转置。

方法:

__len__()
arcsin()逐元素的反正弦函数。
arcsinh()逐元素的反双曲正弦函数。
arctan()逐元素的反正切函数。
arctanh()逐元素的反双曲正切函数。
argmax([axis, out])返回沿轴的最大元素的索引。
argmin([axis, out])返回沿轴的最小元素的索引。
asformat(format[, copy])以指定格式返回此数组/矩阵。
asfptype()将数组/矩阵升级为浮点格式(如果需要)。
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()逐元素向上取整。
check_format([full_check])检查数组/矩阵是否符合 CSR 或 CSC 格式。
conj([copy])逐元素的复共轭。
conjugate([copy])逐元素的复共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零条目的数量,等同于。
deg2rad()逐元素的角度转弧度。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通点乘。
eliminate_zeros()从数组/矩阵中删除零条目。
expm1()逐元素的 expm1。
floor()逐元素的 floor。
getH()返回该数组/矩阵的共轭转置。
get_shape()获取稀疏数组/矩阵的形状。
getcol(j)返回数组/矩阵的第 j 列的副本,作为一个(m x 1)的稀疏数组/矩阵(列向量)。
getformat()稀疏数组/矩阵的存储格式。
getmaxprint()打印时显示的最大元素数量。
getnnz([axis])存储值的数量,包括显式零值。
getrow(i)返回数组/矩阵的第 i 行的副本,作为一个(1 x n)的稀疏数组/矩阵(行向量)。
log1p()逐元素的 log1p。
max([axis, out])返回数组/矩阵的最大值或沿轴的最大值。
maximum(other)该数组/矩阵与另一个数组/矩阵之间的逐元素最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
min([axis, out])返回数组/矩阵的最小值或沿轴的最大值。
minimum(other)该数组/矩阵与另一个数组/矩阵之间的逐元素最小值。
multiply(other)与另一个数组/矩阵、向量或标量进行逐点乘法。
nanmax([axis, out])返回数组/矩阵或沿轴的最大值,忽略任何 NaN 值。
nanmin([axis, out])返回数组/矩阵或沿轴的最小值,忽略任何 NaN 值。
nonzero()数组/矩阵的非零索引。
power(n[, dtype])此函数执行按元素的幂运算。
prune()移除所有非零元素后的空白空间。
rad2deg()按元素进行弧度转角度。
reshape(self, shape[, order, copy])为稀疏数组/矩阵提供新的形状,而不更改其数据。
resize(*shape)就地调整数组/矩阵的尺寸为给定的 shape
rint()按元素四舍五入。
set_shape(shape)参见 reshape
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()按元素求符号。
sin()按元素求正弦。
sinh()按元素求双曲正弦。
sort_indices()原地 对此数组/矩阵的索引进行排序。
sorted_indices()返回此数组/矩阵的索引排序后的副本。
sqrt()按元素求平方根。
sum([axis, dtype, out])沿给定轴对数组/矩阵元素求和。
sum_duplicates()通过将重复条目相加来消除重复条目。
tan()逐元素正切。
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()逐元素截断。
getitem
mul

scipy.sparse.csr_array

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.csr_array.html#scipy.sparse.csr_array

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

压缩稀疏行数组。

可以通过几种方式实例化:

csr_array(D)

其中 D 是一个 2-D ndarray

csr_array(S)

与另一个稀疏数组或矩阵 S 一起(等同于 S.tocsr())

csr_array((M, N), [dtype])

构造一个空数组的形状为(M, N),dtype 是可选的,默认为 dtype='d'。

csr_array((data, (row_ind, col_ind)), [shape=(M, N)])

其中datarow_indcol_ind满足关系a[row_ind[k], col_ind[k]] = data[k]

csr_array((data, indices, indptr), [shape=(M, N)])

是标准的 CSR 表示,其中第 i 行的列索引存储在indices[indptr[i]:indptr[i+1]]中,它们对应的值存储在data[indptr[i]:indptr[i+1]]中。如果未提供形状参数,则从索引数组推断数组维度。

注意事项

稀疏数组可用于算术操作:它们支持加法、减法、乘法、除法和矩阵幂。

CSR 格式的优点

  • 高效的算术操作 CSR + CSR,CSR * CSR 等。

  • 高效的行切片

  • 快速矩阵向量乘积

CSR 格式的缺点

  • 缓慢的列切片操作(考虑 CSC)

  • 更改稀疏结构是昂贵的(考虑 LIL 或 DOK)

规范格式

  • 在每行内,索引按列排序。

  • 没有重复条目。

示例

>>> import numpy as np
>>> from scipy.sparse import csr_array
>>> csr_array((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_array((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
 [0, 0, 3],
 [4, 5, 6]]) 
>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_array((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 2],
 [0, 0, 3],
 [4, 5, 6]]) 

重复条目被合并在一起:

>>> row = np.array([0, 1, 2, 0])
>>> col = np.array([0, 1, 1, 0])
>>> data = np.array([1, 2, 4, 8])
>>> csr_array((data, (row, col)), shape=(3, 3)).toarray()
array([[9, 0, 0],
 [0, 2, 0],
 [0, 4, 0]]) 

作为逐步构建 CSR 数组的示例,以下代码段从文本构建术语-文档数组:

>>> docs = [["hello", "world", "hello"], ["goodbye", "cruel", "world"]]
>>> indptr = [0]
>>> indices = []
>>> data = []
>>> vocabulary = {}
>>> for d in docs:
...     for term in d:
...         index = vocabulary.setdefault(term, len(vocabulary))
...         indices.append(index)
...         data.append(1)
...     indptr.append(len(indices))
...
>>> csr_array((data, indices, indptr), dtype=int).toarray()
array([[2, 1, 0, 0],
 [0, 1, 1, 1]]) 

属性:

dtypedtype

数组的数据类型

shape2-tuple

数组的形状。

ndimint

维数的数量(这总是 2)

nnz

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

size

存储的值的数量。

data

CSR 格式数据数组的索引数组

indices

CSR 格式数组的索引数组

indptr

CSR 格式数组的索引指针数组

has_sorted_indices

索引是否已排序

has_canonical_format

数组/矩阵是否具有排序索引且无重复项

T

转置。

方法

__len__()返回数组/矩阵的长度。
arcsin()元素级的反正弦。
arcsinh()元素级的反双曲正弦。
arctan()元素级的反正切。
arctanh()元素级的反双曲正切。
argmax([axis, out])返回沿着轴的最大元素的索引。
argmin([axis, out])返回沿着轴的最小元素的索引。
asformat(format[, copy])以指定格式返回此数组/矩阵。
asfptype()将数组/矩阵提升为浮点格式(如果需要)。
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()元素级的向上取整。
check_format([full_check])检查数组/矩阵是否符合 CSR 或 CSC 格式。
conj([copy])元素级的复数共轭。
conjugate([copy])元素级的复数共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零条目的数量,等同于。
deg2rad()元素级的角度转弧度。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通点积
eliminate_zeros()从数组/矩阵中删除零条目。
expm1()逐元素的 expm1。
floor()逐元素向下取整。
getH()返回该数组/矩阵的共轭转置。
get_shape()获取稀疏数组/矩阵的形状。
getcol(j)返回数组/矩阵的第 j 列的副本,作为(m x 1)稀疏数组/矩阵(列向量)。
getformat()稀疏数组/矩阵的存储格式。
getmaxprint()打印时显示的最大元素数。
getnnz([axis])存储值的数量,包括显式零值。
getrow(i)返回数组/矩阵的第 i 行的副本,作为(1 x n)稀疏数组/矩阵(行向量)。
log1p()逐元素的 log1p。
max([axis, out])返回数组/矩阵或沿轴的最大值。
maximum(other)该数组/矩阵与另一个数组/矩阵之间的逐元素最大值。
mean([axis, dtype, out])计算沿指定轴的算术平均值。
min([axis, out])返回数组/矩阵或沿轴的最小值。
minimum(other)该数组/矩阵与另一个数组/矩阵之间的逐元素最小值。
multiply(other)与另一个数组/矩阵、向量或标量进行逐点乘法运算。
nanmax([axis, out])返回数组/矩阵的最大值或沿轴的最大值,忽略任何 NaN。
nanmin([axis, out])返回数组/矩阵的最小值或沿轴的最小值,忽略任何 NaN。
nonzero()数组/矩阵的非零元素索引。
power(n[, dtype])此函数执行逐元素的幂运算。
prune()删除所有非零元素后的空白空间。
rad2deg()逐元素的弧度转为角度。
reshape(self, shape[, order, copy])在不改变数据的情况下给稀疏数组/矩阵赋予新的形状。
resize(*shape)在原地将数组/矩阵调整到给定的形状。
rint()逐元素的四舍五入。
set_shape(shape)参见 reshape.
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()逐元素的符号函数。
sin()逐元素的正弦函数。
sinh()逐元素的双曲正弦函数。
sort_indices()就地 对此数组/矩阵的索引进行排序
sorted_indices()返回此数组/矩阵索引排序后的副本
sqrt()逐元素求平方根。
sum([axis, dtype, out])沿指定轴对数组/矩阵元素求和。
sum_duplicates()通过将重复条目相加消除重复条目。
tan()逐元素求正切。
tanh()逐元素双曲正切。
toarray([order, out])返回此稀疏数组/矩阵的密集 ndarray 表示。
tobsr([blocksize, copy])将此数组/矩阵转换为块压缩稀疏行格式。
tocoo([copy])将此数组/矩阵转换为 COO 格式。
tocsc([copy])将此数组/矩阵转换为压缩稀疏列格式。
tocsr([copy])将此数组/矩阵转换为压缩稀疏行格式。
todense([order, out])返回此稀疏数组/矩阵的密集表示。
todia([copy])将此数组/矩阵转换为稀疏 DIAgonal 格式。
todok([copy])将此数组/矩阵转换为键值字典格式。
tolil([copy])将此数组/矩阵转换为列表列表格式。
trace([offset])返回稀疏数组/矩阵对角线上的元素和。
transpose([axes, copy])反转稀疏数组/矩阵的维度。
trunc()逐元素截断。
getitem
mul

scipy.sparse.dia_array

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.dia_array.html#scipy.sparse.dia_array

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

带有 DIAgonal 存储的稀疏数组。

可以通过多种方式实例化:

dia_array(D)

其中 D 是一个 2-D ndarray

dia_array(S)

与另一个稀疏数组或矩阵 S 相同(等同于 S.todia())

dia_array((M, N), [dtype])

用形状为(M, N)构造一个空数组,dtype 是可选的,默认为 dtype='d'。

dia_array((data, offsets), shape=(M, N))

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

注释

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

示例

>>> import numpy as np
>>> from scipy.sparse import dia_array
>>> dia_array((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_array((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_array
>>> n = 10
>>> ex = np.ones(n)
>>> data = np.array([ex, 2 * ex, ex])
>>> offsets = np.array([-1, 0, 1])
>>> dia_array((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.]]) 

属性:

dtypedtype

数组的数据类型

shape2 元组

数组的形状。

ndimint

数组的维数(始终为 2)

nnz

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

size

存储的值的数量。

data

DIA 格式数组的数据数组

offsets

DIA 格式数组的偏移数组

T

转置。

方法

__len__()
arcsin()逐元素的反正弦函数。
arcsinh()逐元素的反双曲正弦函数。
arctan()逐元素的反正切函数。
arctanh()逐元素的反双曲正切函数。
asformat(format[, copy])以传递的格式返回此数组/矩阵。
asfptype()将数组/矩阵升级到浮点格式(如果必要)
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()逐元素向上取整。
conj([copy])逐元素复数共轭。
conjugate([copy])逐元素复数共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零条目的数量,相当于
deg2rad()逐元素 deg2rad。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通的点积。
expm1()逐元素 expm1。
floor()逐元素向下取整。
getH()返回此数组/矩阵的共轭转置。
get_shape()获取稀疏数组/矩阵的形状。
getcol(j)返回数组/矩阵的第 j 列的副本,作为(m x 1)稀疏数组/矩阵(列向量)。
getformat()稀疏数组/矩阵的存储格式。
getmaxprint()打印时显示的最大元素数量。
getnnz([axis])存储值的数量,包括显式零值。
getrow(i)返回数组/矩阵的第 i 行的副本,作为(1 x n)稀疏数组/矩阵(行向量)。
log1p()逐元素 log1p。
maximum(other)该数组/矩阵与另一个数组/矩阵之间的逐元素最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
minimum(other)此数组/矩阵与另一个数组/矩阵之间的逐元素最小值。
multiply(other)与另一个数组/矩阵逐点相乘。
nonzero()数组/矩阵的非零索引。
power(n[, dtype])此函数执行逐元素的幂运算。
rad2deg()逐元素 rad2deg 函数。
reshape(self, shape[, order, copy])给稀疏数组/矩阵赋予新的形状,但不改变其数据。
resize(*shape)原地将数组/矩阵调整为给定形状。
rint()逐元素取整函数。
set_shape(shape)参见 reshape
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()逐元素符号函数。
sin()逐元素 sin 函数。
sinh()逐元素 sinh 函数。
sqrt()逐元素平方根函数。
sum([axis, dtype, out])沿指定轴对数组/矩阵元素求和。
tan()逐元素 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()逐元素截断。
mul

scipy.sparse.dok_array

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.dok_array.html#scipy.sparse.dok_array

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

基于键的字典稀疏数组。

这是一种有效的结构,用于逐步构建稀疏数组。

可以通过几种方式实例化:

dok_array(D)

其中 D 是一个二维 ndarray

dok_array(S)

与另一个稀疏数组或矩阵 S(等效于 S.todok())。

dok_array((M,N), [dtype])

使用初始形状 (M,N) 和 dtype(可选,默认为 dtype='d') 创建数组

注意事项

稀疏数组可用于算术运算:支持加法、减法、乘法、除法和矩阵乘方。

  • 允许高效地 O(1) 访问单个元素。

  • 不允许重复。

  • 构建后可有效地转换为 coo_array。

示例

>>> import numpy as np
>>> from scipy.sparse import dok_array
>>> S = dok_array((5, 5), dtype=np.float32)
>>> for i in range(5):
...     for j in range(5):
...         S[i, j] = i + j    # Update element 

属性:

dtypedtype

数组的数据类型

shape2-元组

数组的形状。

ndimint

维数的数量(这始终是 2)

nnz

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

size

存储值的数量。

T

转置。

方法

asformat(format[, copy])返回用指定格式表示的数组/矩阵。
asfptype()将数组/矩阵提升为浮点格式(如有必要)
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
conj([copy])逐元素复数共轭。
conjtransp()返回共轭转置。
conjugate([copy])逐元素复数共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零条目的数量,相当于
diagonal([k])返回数组/矩阵的第 k 个对角线。
dot(other)普通的点积。
get(key[, default])这覆盖了 dict.get 方法,提供了类型检查但功能上是等效的。
getH()返回该数组/矩阵的共轭转置。
get_shape()获取稀疏数组/矩阵的形状。
getcol(j)返回数组/矩阵的第 j 列的副本,作为(m x 1)稀疏数组/矩阵(列向量)。
getformat()稀疏数组/矩阵的存储格式。
getmaxprint()打印时显示的最大元素数。
getnnz([axis])存储值的数量,包括显式零值。
getrow(i)返回数组/矩阵的第 i 行的副本,作为(1 x n)稀疏数组/矩阵(行向量)。
maximum(other)该数组/矩阵与另一个数组/矩阵之间的逐元素最大值。
mean([axis, dtype, out])计算沿指定轴的算术平均值。
minimum(other)该数组/矩阵与另一个数组/矩阵之间的逐元素最小值。
multiply(other)与另一个数组/矩阵的逐点乘法。
nonzero()数组/矩阵的非零索引。
power(n[, dtype])逐元素的幂。
reshape(self, shape[, order, copy])给稀疏数组/矩阵赋予新的形状,但不改变其数据。
resize(*shape)将数组/矩阵就地调整到由shape给定的尺寸。
set_shape(shape)查看reshape
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sum([axis, dtype, out])对给定轴上的数组/矩阵元素求和。
toarray([order, out])返回此稀疏数组/矩阵的稠密 ndarray 表示。
tobsr([blocksize, copy])将此数组/矩阵转换为块稀疏行格式。
tocoo([copy])将此数组/矩阵转换为坐标格式。
tocsc([copy])将此数组/矩阵转换为压缩稀疏列格式。
tocsr([copy])将此数组/矩阵转换为压缩稀疏行格式。
todense([order, out])返回此稀疏数组/矩阵的稠密表示。
todia([copy])将此数组/矩阵转换为稀疏 DIAgonal 格式。
todok([copy])将此数组/矩阵转换为键字典格式。
tolil([copy])将此数组/矩阵转换为列表列表格式。
trace([offset])返回稀疏数组/矩阵对角线上的元素之和。
transpose([axes, copy])反转稀疏数组/矩阵的维度。
getitem
len
mul
clear
items
keys
popitem
setdefault
update
values

scipy.sparse.lil_array

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.lil_array.html#scipy.sparse.lil_array

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

基于行的列表列表稀疏数组。

这是逐步构建稀疏数组的结构。请注意,在最坏的情况下,插入单个项目可能需要线性时间;为了有效地构建数组,请确保按索引对行进行预排序。

可以通过几种方式实例化:

lil_array(D)

其中 D 是一个 2-D ndarray

lil_array(S)

使用另一个稀疏数组或矩阵 S(等同于 S.tolil())

lil_array((M, N), [dtype])

构造一个形状为(M, N)的空数组,数据类型为可选,默认为 dtype=’d’。

注意事项

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

LIL 格式的优点

  • 支持灵活的切片

  • 更改数组稀疏结构是高效的

LIL 格式的缺点

  • 算术运算 LIL + LIL 很慢(考虑 CSR 或 CSC)

  • 缓慢的列切片(考虑 CSC)

  • 缓慢的矩阵向量乘积(考虑 CSR 或 CSC)

预期用途

  • LIL 是构造稀疏数组的便利格式

  • 一旦构造了数组,将其转换为 CSR 或 CSC 格式以进行快速的算术和矩阵向量操作

  • 在构造大型数组时考虑使用 COO 格式

数据结构

  • 一个数组(self.rows),每个都是非零元素的列索引的排序列表的行。

  • 相应的非零值以类似的方式存储在self.data中。

属性:

dtype数据类型

数组的数据类型

shape2-元组

数组的形状。

ndim整数

维度数量(这始终是 2)

nnz

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

size

存储的值的数量。

data

LIL 格式的数据数组

rows

LIL 格式的行索引数组

T

转置。

方法

__len__()
asformat(format[, copy])将该数组/矩阵以指定格式返回。
asfptype()将数组/矩阵向浮点格式转换(如果需要)
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
conj([copy])按元素复数共轭。
conjugate([copy])按元素复数共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零条目的数量,相当于。
diagonal([k])返回数组/矩阵的第 k 个对角线。
dot(other)普通点积。
getH()返回此数组/矩阵的共轭转置。
get_shape()获取稀疏数组/矩阵的形状。
getcol(j)返回数组/矩阵的第 j 列的副本,作为(m x 1)稀疏数组/矩阵(列向量)。
getformat()稀疏数组/矩阵的存储格式。
getmaxprint()打印时显示的最大元素数。
getnnz([axis])存储值的数量,包括显式零值。
getrow(i)返回第'i'行的副本。
getrowview(i)返回第'i'行的视图(不复制)。
maximum(other)数组/矩阵与另一个数组/矩阵之间的按元素最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
minimum(other)该数组/矩阵与另一个数组/矩阵逐元素取最小值
multiply(other)与另一个数组/矩阵进行逐元素相乘
nonzero()返回数组/矩阵中非零元素的索引位置
power(n[, dtype])逐元素求幂
reshape(self, shape[, order, copy])为稀疏数组/矩阵提供新的形状,不改变其数据
resize(*shape)调整数组/矩阵到给定shape的尺寸
set_shape(shape)参见reshape
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素
sum([axis, dtype, out])沿指定轴对数组/矩阵元素求和
toarray([order, out])返回该稀疏数组/矩阵的密集 ndarray 表示
tobsr([blocksize, copy])将该数组/矩阵转换为块稀疏行格式
tocoo([copy])将该数组/矩阵转换为 COO 格式
tocsc([copy])将该数组/矩阵转换为压缩稀疏列格式
tocsr([copy])将该数组/矩阵转换为压缩稀疏行格式
todense([order, out])返回该稀疏数组/矩阵的密集表示
todia([copy])将该数组/矩阵转换为稀疏对角格式
todok([copy])将此数组/矩阵转换为键字典格式。
tolil([copy])将此数组/矩阵转换为列表列表格式。
trace([offset])返回稀疏数组/矩阵沿对角线的和。
transpose([axes, copy])反转稀疏数组/矩阵的维度。
getitem
mul

scipy.sparse.sparray

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.sparray.html#scipy.sparse.sparray

class scipy.sparse.sparray

This class provides a base class for all sparse arrays. It cannot be instantiated. Most of the work is provided by subclasses.

scipy.sparse.bsr_matrix

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.bsr_matrix.html#scipy.sparse.bsr_matrix

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

块稀疏行格式稀疏矩阵。

这可以通过几种方式实现:

bsr_matrix(D, [blocksize=(R,C)])

其中 D 是 2D ndarray。

bsr_matrix(S, [blocksize=(R,C)])

与另一个稀疏数组或矩阵 S(等同于 S.tobsr())

bsr_matrix((M, N), [blocksize=(R,C), dtype])

用于构造形状为(M,N)的空稀疏矩阵,dtype 是可选的,默认为 dtype='d'。

bsr_matrix((data, ij), [blocksize=(R,C), shape=(M, N)])

dataij满足a[ij[0, k], ij[1, k]] = data[k]

bsr_matrix((data, indices, indptr), [shape=(M, N)])

是标准的 BSR 表示,其中第 i 行的块列索引存储在indices[indptr[i]:indptr[i+1]]中,并且它们对应的块值存储在data[indptr[i]:indptr[i+1]]中。如果未提供形状参数,则从索引数组中推断出矩阵的维度。

注意事项

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

BSR 格式总结

块稀疏行(BSR)格式与压缩稀疏行(CSR)格式非常相似。BSR 适用于具有稠密子矩阵的稀疏矩阵,例如下面的最后一个示例。这种稀疏块矩阵经常出现在向量值有限元离散化中。在这些情况下,对于许多稀疏算术运算,BSR 比 CSR 和 CSC 更有效率。

块大小

块大小(R,C)必须均匀地划分稀疏矩阵的形状(M,N)。也就是说,R 和 C 必须满足关系M % R = 0N % C = 0

如果未指定块大小,则将应用简单的启发式方法来确定适当的块大小。

规范格式

在规范格式中,没有重复的块,并且每行的索引都是排序的。

示例

>>> import numpy as np
>>> from scipy.sparse import bsr_matrix
>>> bsr_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3 ,4, 5, 6])
>>> bsr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
 [0, 0, 3],
 [4, 5, 6]]) 
>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6]).repeat(4).reshape(6, 2, 2)
>>> bsr_matrix((data,indices,indptr), shape=(6, 6)).toarray()
array([[1, 1, 0, 0, 2, 2],
 [1, 1, 0, 0, 2, 2],
 [0, 0, 0, 0, 3, 3],
 [0, 0, 0, 0, 3, 3],
 [4, 4, 5, 5, 6, 6],
 [4, 4, 5, 5, 6, 6]]) 

属性:

dtype数据类型

矩阵的数据类型

shape2 元组

矩阵的形状

ndim整型

维度数量(始终为 2)

nnz

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

size

存储的值数量。

data

BSR 格式矩阵的数据数组

indices

BSR 格式矩阵的索引数组

indptr

BSR 格式矩阵的索引指针数组

blocksize

矩阵的块大小。

has_sorted_indicesbool

索引是否已排序

has_canonical_formatbool

数组/矩阵是否具有排序的索引且无重复

T

转置。

方法

__len__()
__mul__(other)
arcsin()逐元素反正弦函数。
arcsinh()逐元素反双曲正弦函数。
arctan()逐元素反正切函数。
arctanh()逐元素反双曲正切函数。
argmax([axis, out])返回沿轴的最大元素的索引。
argmin([axis, out])返回沿轴的最小元素的索引。
asformat(format[, copy])以指定格式返回此数组/矩阵。
asfptype()将矩阵提升为浮点数格式(如有必要)。
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()逐元素向上取整。
check_format([full_check])检查数组/矩阵是否符合 BSR 格式。
conj([copy])逐元素复数共轭。
conjugate([copy])逐元素复数共轭。
copy()返回该数组/矩阵的副本。
count_nonzero()非零条目的数量,等同于。
deg2rad()逐元素的角度转弧度。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通的点积。
eliminate_zeros()去除矩阵中的零元素(就地操作)。
expm1()逐元素的 expm1。
floor()逐元素的 floor。
getH()返回该矩阵的共轭转置。
get_shape()获取矩阵的形状。
getcol(j)返回矩阵的第 j 列的副本,作为一个 (m x 1) 稀疏矩阵(列向量)。
getformat()矩阵存储格式。
getmaxprint()打印时显示的最大元素数。
getnnz([axis])存储的值的数量,包括显式的零。
getrow(i)返回矩阵的第 i 行的副本,作为 (1 x n) 稀疏矩阵(行向量)。
log1p()逐元素的 log1p。
max([axis, out])返回数组/矩阵的最大值或沿轴的最大值。
maximum(other)此矩阵和另一个数组/矩阵之间的逐元素最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
min([axis, out])返回数组/矩阵或指定轴向的最小值。
minimum(other)此矩阵和另一个数组/矩阵之间的逐元素最小值。
multiply(other)逐点乘以另一个数组/矩阵、向量或标量。
nanmax([axis, out])返回数组/矩阵或指定轴向的最大值,忽略任何 NaN 值。
nanmin([axis, out])返回数组/矩阵或指定轴向的最小值,忽略任何 NaN 值。
nonzero()数组/矩阵的非零索引。
power(n[, dtype])此函数执行逐元素的幂运算。
prune()移除所有非零元素后的空白空间。
rad2deg()逐元素将弧度转换为角度。
reshape(self, shape[, order, copy])将稀疏数组/矩阵重新整形为新的形状,但不改变其数据。
resize(*shape)原地调整数组/矩阵的维度为给定的 shape
rint()逐元素四舍五入。
set_shape(shape)在原地设置矩阵的形状。
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()逐元素求符号。
sin()逐元素求正弦。
sinh()逐元素求双曲正弦。
sort_indices()原地 对此数组/矩阵的索引进行排序。
sorted_indices()返回按排序索引的此数组/矩阵的副本。
sqrt()逐元素求平方根。
sum([axis, dtype, out])沿给定轴对数组/矩阵元素求和。
sum_duplicates()通过将重复的数组/矩阵条目相加来消除重复项。
tan()逐元素求正切。
tanh()逐元素求双曲正切。
toarray([order, out])返回此稀疏数组/矩阵的密集 ndarray 表示。
tobsr([blocksize, copy])将此数组/矩阵转换为块稀疏行格式。
tocoo([copy])将此数组/矩阵转换为 COO 格式。
tocsc([copy])将此数组/矩阵转换为压缩稀疏列格式。
tocsr([copy])将此数组/矩阵转换为压缩稀疏行格式。
todense([order, out])返回此稀疏数组/矩阵的密集表示。
todia([copy])将此数组/矩阵转换为稀疏对角格式。
todok([copy])将此数组/矩阵转换为字典键格式。
tolil([copy])将此数组/矩阵转换为列表列表格式。
trace([offset])返回稀疏数组/矩阵沿对角线的和。
transpose([axes, copy])反转稀疏数组/矩阵的维度。
trunc()逐元素截断。
getitem

scipy.sparse.coo_matrix

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.coo_matrix.html#scipy.sparse.coo_matrix

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

COO 格式中的稀疏矩阵。

也称为 'ijv' 或 'triplet' 格式。

这可以通过几种方式实例化:

coo_matrix(D)

其中 D 是 2-D 数组

coo_matrix(S)

与另一个稀疏数组或矩阵 S 进行操作(等同于 S.tocoo())

coo_matrix((M, N), [dtype])

用于构造形状为 (M, N) 的空矩阵,数据类型是可选的,默认为 dtype='d'。

coo_matrix((data, (i, j)), [shape=(M, N)])

从三个数组构造:

  1. data[:] 矩阵的条目,按任意顺序排列

  2. i[:] 矩阵条目的行索引

  3. j[:] 矩阵条目的列索引

当未指定形状时,从索引数组推断。

注意事项

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

COO 格式的优点

  • 促进稀疏格式之间的快速转换

  • 允许重复条目(见示例)

  • 非常快速地转换为 CSR/CSC 格式和从中转换

COO 格式的缺点

  • 不直接支持:

    • 算术操作

    • 切片

预期用途

  • COO 是构造稀疏矩阵的快速格式

  • 一旦构造了 COO 矩阵,将其转换为 CSR 或 CSC 格式以进行快速算术和矩阵向量操作

  • 默认情况下,在转换为 CSR 或 CSC 格式时,重复的 (i,j) 条目将被汇总在一起。这有助于高效地构造有限元矩阵等(见示例)

规范格式

  • 条目和索引按行、列排序。

  • 没有重复条目(即重复的 (i,j) 位置)

  • 数据数组可以具有显式的零。

示例

>>> # Constructing an empty matrix
>>> import numpy as np
>>> from scipy.sparse import coo_matrix
>>> coo_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> # Constructing a matrix using ijv format
>>> row  = np.array([0, 3, 1, 0])
>>> col  = np.array([0, 3, 1, 2])
>>> data = np.array([4, 5, 7, 9])
>>> coo_matrix((data, (row, col)), shape=(4, 4)).toarray()
array([[4, 0, 9, 0],
 [0, 7, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 5]]) 
>>> # Constructing a matrix with duplicate indices
>>> row  = np.array([0, 0, 1, 3, 1, 0, 0])
>>> col  = np.array([0, 2, 1, 3, 1, 0, 0])
>>> data = np.array([1, 1, 1, 1, 1, 1, 1])
>>> coo = coo_matrix((data, (row, col)), shape=(4, 4))
>>> # Duplicate indices are maintained until implicitly or explicitly summed
>>> np.max(coo.data)
1
>>> coo.toarray()
array([[3, 0, 1, 0],
 [0, 2, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 1]]) 

属性:

dtype数据类型

矩阵的数据类型

shape2-元组

矩阵的形状

ndim整数

维度的数量(这总是 2)

nnz

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

size

存储值的数量。

数据

COO 格式矩阵的数据数组

COO 格式矩阵的行索引数组

COO 格式矩阵的列索引数组

has_canonical_format布尔值

矩阵是否具有排序的索引且无重复项

format

矩阵的格式化字符串。

T

转置。

方法

__len__()
__mul__(other)
arcsin()逐元素反正弦函数。
arcsinh()逐元素反双曲正弦函数。
arctan()逐元素反正切函数。
arctanh()逐元素反双曲正切函数。
argmax([axis, out])返回沿轴的最大元素的索引。
argmin([axis, out])返回沿轴的最小元素的索引。
asformat(format[, copy])以指定格式返回此数组/矩阵。
asfptype()将矩阵升级为浮点数格式(如有必要)。
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()逐元素向上取整。
conj([copy])逐元素复共轭。
conjugate([copy])逐元素复共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零元素的数量,相当于
deg2rad()逐元素角度转弧度。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通的点积。
eliminate_zeros()从数组/矩阵中删除零条目。
expm1()逐元素的 expm1。
floor()逐元素向下取整。
getH()返回该矩阵的共轭转置。
get_shape()获取矩阵的形状。
getcol(j)返回矩阵的第 j 列的副本,作为(m x 1)稀疏矩阵(列向量)。
getformat()矩阵存储格式。
getmaxprint()打印时显示的最大元素数。
getnnz([axis])存储的值的数量,包括显式的零。
getrow(i)返回矩阵的第 i 行的副本,作为(1 x n)稀疏矩阵(行向量)。
log1p()逐元素的 log1p。
max([axis, out])返回数组/矩阵的最大值或沿轴的最大值。
maximum(other)该矩阵与另一个数组/矩阵之间的逐元素最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
min([axis, out])返回数组/矩阵的最小值或沿轴的最小值。
minimum(other)该矩阵与另一个数组/矩阵之间的逐元素最小值。
multiply(other)与另一个数组/矩阵进行逐点乘法。
nanmax([axis, out])返回数组/矩阵或沿轴的最大值,忽略任何 NaN。
nanmin([axis, out])返回数组/矩阵或沿轴的最小值,忽略任何 NaN。
nonzero()数组/矩阵的非零索引。
power(n[, dtype])对数组/矩阵进行逐点幂运算。
rad2deg()元素逐个将弧度转换为角度。
reshape(self, shape[, order, copy])为稀疏数组/矩阵赋予新的形状,但不改变其数据。
resize(*shape)原地调整数组/矩阵的形状为给定的 shape
rint()元素逐个四舍五入。
set_shape(shape)原地设置矩阵的形状。
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()元素逐个取符号。
sin()元素逐个求正弦。
sinh()元素逐个求双曲正弦。
sqrt()元素逐个求平方根。
sum([axis, dtype, out])沿给定轴对数组/矩阵元素求和。
sum_duplicates()通过将重复的条目相加来消除重复条目。
tan()逐元素的正切函数。
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()逐元素的截断函数。

scipy.sparse.csc_matrix

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.csc_matrix.html#scipy.sparse.csc_matrix

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

压缩稀疏列矩阵。

可以通过几种方式实例化:

csc_matrix(D)

其中 D 是一个二维 ndarray

csc_matrix(S)

与另一个稀疏数组或矩阵 S(等同于 S.tocsc())

csc_matrix((M, N), [dtype])

用于构建形状为 (M, N) 的空矩阵,dtype 可选,默认为 dtype='d'。

csc_matrix((data, (row_ind, col_ind)), [shape=(M, N)])

其中 datarow_indcol_ind 满足关系 a[row_ind[k], col_ind[k]] = data[k]

csc_matrix((data, indices, indptr), [shape=(M, N)])

是标准的 CSC 表示,其中第 i 列的行索引存储在 indices[indptr[i]:indptr[i+1]],它们对应的值存储在 data[indptr[i]:indptr[i+1]]。如果未提供 shape 参数,则从索引数组推断出矩阵的维度。

注释

稀疏矩阵可以用于算术运算:支持加法、减法、乘法、除法和矩阵乘方。

CSC 格式的优点

  • 高效的算术运算 CSC + CSC,CSC * CSC 等。

  • 高效的列切片

  • 快速的矩阵向量乘法(CSR,BSR 可能更快)

CSC 格式的缺点

  • 缓慢的行切片操作(考虑 CSR)

  • 对稀疏结构的更改代价高昂(考虑 LIL 或 DOK)

规范格式

  • 每列内的索引按行排序。

  • 没有重复的条目。

示例

>>> import numpy as np
>>> from scipy.sparse import csc_matrix
>>> csc_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> row = np.array([0, 2, 2, 0, 1, 2])
>>> col = np.array([0, 0, 1, 2, 2, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csc_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 4],
 [0, 0, 5],
 [2, 3, 6]]) 
>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csc_matrix((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 4],
 [0, 0, 5],
 [2, 3, 6]]) 

属性:

dtype数据类型

矩阵的数据类型

shape的二元组

矩阵的形状

ndim整数

维度数量(始终为 2)

nnz

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

size

存储值的数量

data

CSC 格式矩阵的数据数组

indices

CSC 格式矩阵的索引数组

indptr

CSC 格式矩阵的索引指针数组

has_sorted_indices

索引是否已排序

has_canonical_format

数组/矩阵是否具有排序的索引且无重复

T

转置。

方法

__len__()
__mul__
arcsin()逐元素反正弦。
arcsinh()逐元素反双曲正弦。
arctan()逐元素反正切。
arctanh()逐元素反双曲正切。
argmax([axis, out])返回沿轴的最大元素的索引。
argmin([axis, out])返回沿轴的最小元素的索引。
asformat(format[, copy])以指定格式返回此数组/矩阵。
asfptype()将矩阵提升为浮点格式(如有必要)
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()逐元素向上取整。
check_format([full_check])检查数组/矩阵是否符合 CSR 或 CSC 格式。
conj([copy])逐元素复数共轭。
conjugate([copy])逐元素复数共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零条目的数量,等效于
deg2rad()逐元素角度转弧度。
diagonal([k])返回数组/矩阵的第 k 个对角线。
dot(other)普通的点积。
eliminate_zeros()从数组/矩阵中删除零条目。
expm1()逐元素的 expm1。
floor()逐元素向下取整。
getH()返回该矩阵的共轭转置。
get_shape()获取矩阵的形状。
getcol(j)返回矩阵的第 j 列副本,作为(m x 1)稀疏矩阵(列向量)。
getformat()矩阵存储格式。
getmaxprint()打印时显示的最大元素数量。
getnnz([axis])存储的值的数量,包括显式的零值。
getrow(i)返回矩阵的第 i 行副本,作为(1 x n)稀疏矩阵(行向量)。
log1p()逐元素的 log1p。
max([axis, out])返回数组/矩阵的最大值或沿轴的最大值。
maximum(other)该数组/矩阵与另一个数组/矩阵的逐元素最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
min([axis, out])返回数组/矩阵的最小值或沿轴的最小值。
minimum(other)该数组/矩阵与另一个数组/矩阵的逐元素最小值。
multiply(other)与另一个数组/矩阵、向量或标量进行逐点乘法。
nanmax([axis, out])返回数组/矩阵的最大值或沿轴的最大值,忽略任何 NaN 值。
nanmin([axis, out])返回数组/矩阵的最小值或沿轴的最小值,忽略任何 NaN 值。
nonzero()返回数组/矩阵的非零索引。
power(n[, dtype])此函数执行逐元素的幂运算。
prune()删除所有非零元素后的空白空间。
rad2deg()逐元素弧度转角度。
reshape(self, shape[, order, copy])在不改变数据的情况下,为稀疏数组/矩阵提供新的形状。
resize(*shape)将数组/矩阵原地调整大小为给定的shape维度。
rint()逐元素四舍五入。
set_shape(shape)原地设置矩阵的形状。
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()逐元素取符号。
sin()逐元素求正弦值。
sinh()逐元素求双曲正弦值。
sort_indices()原地对此数组/矩阵的索引进行排序。
sorted_indices()返回此数组/矩阵的带有排序索引的副本。
sqrt()元素级的平方根函数。
sum([axis, dtype, out])沿指定轴对数组/矩阵元素求和。
sum_duplicates()通过将重复条目相加来消除重复条目。
tan()元素级的正切函数。
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()元素级的截断函数。
getitem

scipy.sparse.csr_matrix

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.sparse.csr_matrix.html#scipy.sparse.csr_matrix

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

压缩稀疏行(CSR)矩阵。

可以通过几种方式实例化:

csr_matrix(D)

其中 D 是一个二维 ndarray

csr_matrix(S)

与另一个稀疏数组或矩阵 S 进行操作(等同于 S.tocsr())

csr_matrix((M, N), [dtype])

以形状(M,N)实例化空矩阵时,数据类型是可选的,默认为 dtype=’d’。

csr_matrix((data, (row_ind, col_ind)), [shape=(M, N)])

其中 datarow_indcol_ind 满足关系 a[row_ind[k], col_ind[k]] = data[k]

csr_matrix((data, indices, indptr), [shape=(M, N)])

是标准的 CSR 表示,其中行 i 的列索引存储在 indices[indptr[i]:indptr[i+1]] 中,并且它们对应的值存储在 data[indptr[i]:indptr[i+1]] 中。如果未提供形状参数,则从索引数组中推断出矩阵的维度。

注释

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

CSR 格式的优势

  • 高效的算术操作 CSR + CSR,CSR * CSR 等。

  • 高效的行切片

  • 快速矩阵向量乘积

CSR 格式的缺点

  • 缓慢的列切片操作(考虑 CSC)

  • 更改稀疏结构的代价高昂(考虑 LIL 或 DOK)

规范格式

  • 每行内部的索引按列排序。

  • 没有重复条目。

示例

>>> import numpy as np
>>> from scipy.sparse import csr_matrix
>>> csr_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]], dtype=int8) 
>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
 [0, 0, 3],
 [4, 5, 6]]) 
>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_matrix((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 2],
 [0, 0, 3],
 [4, 5, 6]]) 

重复条目将被合并:

>>> row = np.array([0, 1, 2, 0])
>>> col = np.array([0, 1, 1, 0])
>>> data = np.array([1, 2, 4, 8])
>>> csr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[9, 0, 0],
 [0, 2, 0],
 [0, 4, 0]]) 

作为逐步构建 CSR 矩阵的示例,以下代码段从文本构建术语-文档矩阵:

>>> docs = [["hello", "world", "hello"], ["goodbye", "cruel", "world"]]
>>> indptr = [0]
>>> indices = []
>>> data = []
>>> vocabulary = {}
>>> for d in docs:
...     for term in d:
...         index = vocabulary.setdefault(term, len(vocabulary))
...         indices.append(index)
...         data.append(1)
...     indptr.append(len(indices))
...
>>> csr_matrix((data, indices, indptr), dtype=int).toarray()
array([[2, 1, 0, 0],
 [0, 1, 1, 1]]) 

属性:

dtype 数据类型

矩阵的数据类型

shape 2-元组

矩阵的形状

ndimint

维度数(始终为 2)

nnz

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

size

存储的值的数量。

data

CSR 格式矩阵的数据数组

indices

CSR 格式矩阵的索引数组

indptr

CSR 格式矩阵的索引指针数组

has_sorted_indices

索引是否已排序

has_canonical_format

数组/矩阵是否具有排序的索引且无重复项

T

转置。

方法

__len__()
__mul__(other)
arcsin()元素级反正弦。
arcsinh()元素级反双曲正弦。
arctan()元素级反正切。
arctanh()元素级反双曲正切。
argmax([axis, out])沿轴返回最大元素的索引。
argmin([axis, out])沿轴返回最小元素的索引。
asformat(format[, copy])以指定格式返回此数组/矩阵。
asfptype()将矩阵升级为浮点格式(如果需要)
astype(dtype[, casting, copy])将数组/矩阵元素转换为指定类型。
ceil()元素级向上取整。
check_format([full_check])检查数组/矩阵是否符合 CSR 或 CSC 格式。
conj([copy])元素级复数共轭。
conjugate([copy])元素级复数共轭。
copy()返回此数组/矩阵的副本。
count_nonzero()非零元素的数量,相当于
deg2rad()元素级角度转弧度。
diagonal([k])返回数组/矩阵的第 k 条对角线。
dot(other)普通的点积。
eliminate_zeros()从数组/矩阵中删除零条目。
expm1()逐元素的 expm1 运算。
floor()逐元素的 floor 运算。
getH()返回该矩阵的共轭转置。
get_shape()获取矩阵的形状。
getcol(j)返回矩阵第 j 列的副本,作为(m x 1)稀疏矩阵(列向量)。
getformat()矩阵存储格式。
getmaxprint()打印时显示的最大元素数量。
getnnz([axis])存储值的数量,包括显式的零值。
getrow(i)返回矩阵第 i 行的副本,作为(1 x n)稀疏矩阵(行向量)。
log1p()逐元素的 log1p 运算。
max([axis, out])返回数组/矩阵的最大值或沿轴的最大值。
maximum(other)该数组/矩阵与另一个数组/矩阵的逐元素最大值。
mean([axis, dtype, out])沿指定轴计算算术平均值。
min([axis, out])返回数组/矩阵的最小值或沿轴的最小值。
minimum(other)与另一个数组/矩阵之间的逐元素最小值。
multiply(other)与另一个数组/矩阵、向量或标量的逐点乘积。
nanmax([axis, out])返回数组/矩阵或沿轴的最大值,忽略任何 NaN 值。
nanmin([axis, out])返回数组/矩阵或沿轴的最小值,忽略任何 NaN 值。
nonzero()数组/矩阵的非零索引。
power(n[, dtype])执行逐元素的幂运算。
prune()移除所有非零元素后的空白空间。
rad2deg()逐元素的 rad2deg。
reshape(self, shape[, order, copy])在不改变数据的情况下,为稀疏数组/矩阵提供新的形状。
resize(*shape)原地调整数组/矩阵的形状为给定的 shape
rint()逐元素的 rint。
set_shape(shape)原地设置矩阵的形状。
setdiag(values[, k])设置数组/矩阵的对角线或非对角线元素。
sign()逐元素的符号。
sin()逐元素的 sin。
sinh()逐元素的 sinh。
sort_indices()原地对数组/矩阵的索引进行排序。
sorted_indices()返回按索引排序的稀疏数组/矩阵的副本。
sqrt()逐元素的平方根函数。
sum([axis, dtype, out])沿着给定轴对数组/矩阵元素求和。
sum_duplicates()通过将重复条目相加来消除重复条目。
tan()逐元素的正切函数。
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()按元素截断。
getitem