cupyx.scipy.sparse.diags#

cupyx.scipy.sparse.diags(diagonals, offsets=0, shape=None, format=None, dtype=None)[源代码][源代码]#

从对角线构造一个稀疏矩阵。

参数:
  • diagonals (sequence of array_like) – 包含矩阵对角线的数组序列,对应于 offsets

  • offsets (sequence of int or an int) – 要设置的对角线: - k = 0 主对角线(默认) - k > 0 k-th 上对角线 - k < 0 k-th 下对角线

  • shape (tuple of int) – 结果的形状。如果省略,将返回一个足够大的方形矩阵以包含对角线。

  • format ({"dia", "csr", "csc", "lil", ...}) – 结果的矩阵格式。默认情况下(format=None),将返回适当的稀疏矩阵格式。此选择可能会更改。

  • dtype (dtype) – 矩阵的数据类型。

返回:

生成的矩阵。

返回类型:

cupyx.scipy.sparse.spmatrix

备注

此函数与 spdiags 在处理非对角线元素的方式上有所不同。

diags 的结果是以下内容的稀疏等价物:

cupy.diag(diagonals[0], offsets[0])
+ ...
+ cupy.diag(diagonals[k], offsets[k])

不允许重复的对角偏移。