cupyx.scipy.sparse.dia_matrix#

class cupyx.scipy.sparse.dia_matrix(*args, maxprint=50, **kwargs)[source]#

Sparse matrix with DIAgonal storage.

Methods

__len__()[source]#
__iter__()[source]#
arcsin()[source]#

Elementwise arcsin.

arcsinh()[source]#

Elementwise arcsinh.

arctan()[source]#

Elementwise arctan.

arctanh()[source]#

Elementwise arctanh.

asformat(format)[source]#

Return this matrix in a given sparse format.

Parameters:

format (str or None) – Format you need.

asfptype()[source]#

Upcasts matrix to a floating point format.

When the matrix has floating point type, the method returns itself. Otherwise it makes a copy with floating point type and the same format.

Returns:

A matrix with float type.

Return type:

cupyx.scipy.sparse.spmatrix

astype(dtype, copy=True)[source]#

Cast the array elements to a specified type.

Parameters:
  • dtype – Target dtype.

  • copy (bool) – If True (default), the returned array does not share memory with self. If False, self is returned unchanged when the dtype already matches.

Returns:

Sparse object with the requested dtype and the same format.

ceil()[source]#

Elementwise ceil.

conj(copy=True)[source]#

Element-wise complex conjugation.

If the matrix is of non-complex data type and copy is False, this method does nothing and the data is not copied.

Parameters:

copy (bool) – If True, the result is guaranteed to not share data with self.

Returns:

The element-wise complex conjugate.

Return type:

cupyx.scipy.sparse.spmatrix

conjugate(copy=True)[source]#

Element-wise complex conjugation.

If the matrix is of non-complex data type and copy is False, this method does nothing and the data is not copied.

Parameters:

copy (bool) – If True, the result is guaranteed to not share data with self.

Returns:

The element-wise complex conjugate.

Return type:

cupyx.scipy.sparse.spmatrix

copy()[source]#

Returns a copy of this matrix.

No data/indices will be shared between the returned value and current matrix.

count_nonzero(axis=None)[source]#

Number of non-zero entries.

Excludes explicit zeros and entries that lie outside the matrix shape (DIA’s data buffer can be wider than num_cols; those pad entries don’t count). DIA doesn’t support per-axis counts – use tocsr().count_nonzero(axis).

deg2rad()[source]#

Elementwise deg2rad.

diagonal(k=0)[source]#

Returns the k-th diagonal of the matrix.

Parameters:
  • k (int, optional) – Which diagonal to get, corresponding to elements

  • a[i – 0 (the main diagonal).

  • Default (i+k].) – 0 (the main diagonal).

Returns:

The k-th diagonal.

Return type:

cupy.ndarray

dot(other)[source]#

Ordinary dot product

expm1()[source]#

Elementwise expm1.

floor()[source]#

Elementwise floor.

get(stream=None)[source]#

Returns a copy of the array on host memory.

Parameters:

stream (cupy.cuda.Stream) – CUDA stream object. If it is given, the copy runs asynchronously. Otherwise, the copy is synchronous.

Returns:

Copy of the array on host memory.

Return type:

scipy.sparse.dia_matrix

getH()[source]#

Hermitian (conjugate) transpose of this matrix.

get_shape()[source]#

Return the shape of the matrix.

getcol(j)[source]#

Return a copy of column j as a (m x 1) sparse column vector.

Matrix-only API; for sparse arrays use A[:, j] (or A[:, [j]] for a 2-D result).

getformat()[source]#

Return the format string of this matrix (e.g. 'csr').

getmaxprint()[source]#

Return the maximum number of stored values shown in __str__.

getnnz(axis=None)[source]#

Number of stored values, including explicit zeros.

Parameters:

axis (None, 0, or 1) – Select between the number of values across the whole matrix, in each column (axis=0), or in each row (axis=1).

getrow(i)[source]#

Return a copy of row i as a (1 x n) sparse row vector.

Matrix-only API; for sparse arrays use A[i] (or A[[i], :] for a 2-D result).

log1p()[source]#

Elementwise log1p.

maximum(other)[source]#
mean(axis=None, dtype=None, out=None)[source]#

Compute the arithmetic mean along the specified axis.

Parameters:

axis (int or None) – Axis along which the sum is computed. If it is None, it computes the average of all the elements. Select from {None, 0, 1, -2, -1}.

Returns:

Summed array.

Return type:

cupy.ndarray

See also

scipy.sparse.spmatrix.mean()

minimum(other)[source]#
multiply(other)[source]#

Point-wise multiplication by another matrix

nonzero()[source]#

Indices of the non-zero elements.

Returns a tuple (row, col) of cupy.ndarrays (matching scipy.sparse._base._spbase.nonzero()). Explicit zeros are excluded.

power(n, dtype=None)[source]#

Elementwise power function.

Parameters:
  • n – Exponent.

  • dtype – Type specifier.

rad2deg()[source]#

Elementwise rad2deg.

reshape(*shape, order='C')[source]#

Gives a new shape to a sparse matrix without changing its data.

Parameters:
  • shape (tuple) – The new shape should be compatible with the original shape.

  • order – {‘C’, ‘F’} (optional) Read the elements using this index order. ‘C’ means to read and write the elements using C-like index order. ‘F’ means to read and write the elements using Fortran-like index order. Default: C.

Returns:

sparse matrix

Return type:

cupyx.scipy.sparse.coo_matrix

rint()[source]#

Elementwise rint.

set_shape(shape)[source]#

Set the shape of the matrix in-place.

setdiag(values, k=0)[source]#

Set diagonal or off-diagonal elements of the array.

Parameters:
  • values (cupy.ndarray) – New values of the diagonal elements. Values may have any length. If the diagonal is longer than values, then the remaining diagonal entries will not be set. If values is longer than the diagonal, then the remaining values are ignored. If a scalar value is given, all of the diagonal is set to it.

  • k (int, optional) – Which diagonal to set, corresponding to elements a[i, i+k]. Default: 0 (the main diagonal).

sign()[source]#

Elementwise sign.

sin()[source]#

Elementwise sin.

sinh()[source]#

Elementwise sinh.

sqrt()[source]#

Elementwise sqrt.

sum(axis=None, dtype=None, out=None)[source]#

Sums the matrix elements over a given axis.

Parameters:
  • axis (int or None) – Axis along which the sum is computed. If it is None, it computes the sum of all the elements. Select from {None, 0, 1, -2, -1}.

  • dtype – The type of returned matrix. If it is not specified, type of the array is used.

  • out (cupy.ndarray) – Output matrix.

Returns:

Summed array.

Return type:

cupy.ndarray

See also

scipy.sparse.spmatrix.sum()

tan()[source]#

Elementwise tan.

tanh()[source]#

Elementwise tanh.

toarray(order=None, out=None)[source]#

Returns a dense matrix representing the same value.

tobsr(blocksize=None, copy=False)[source]#

Convert this matrix to Block Sparse Row format.

tocoo(copy=False)[source]#

Convert this matrix to COOrdinate format.

tocsc(copy=False)[source]#

Converts the matrix to Compressed Sparse Column format.

Parameters:

copy (bool) – If False, it shares data arrays as much as possible. Actually this option is ignored because all arrays in a matrix cannot be shared in dia to csc conversion.

Returns:

Converted matrix.

Return type:

cupyx.scipy.sparse.csc_matrix

tocsr(copy=False)[source]#

Converts the matrix to Compressed Sparse Row format.

Parameters:

copy (bool) – If False, it shares data arrays as much as possible. Actually this option is ignored because all arrays in a matrix cannot be shared in dia to csr conversion.

Returns:

Converted matrix.

Return type:

cupyx.scipy.sparse.csc_matrix

todense(order=None, out=None)[source]#

Return a dense matrix representation of this matrix.

todia(copy=False)[source]#

Return this object unchanged (already in DIA format).

The base _spbase.todia would round-trip via CSR, which is unnecessary work and currently raises NotImplementedError because csr_matrix.todia() is unimplemented.

Parameters:

copy (bool) – If True, return a copy.

todok(copy=False)[source]#

Convert this matrix to Dictionary Of Keys format.

tolil(copy=False)[source]#

Convert this matrix to LInked List format.

trace(offset=0)[source]#

Returns the sum along diagonals of the sparse matrix.

Parameters:

offset (int) – Which diagonal to get. Default: 0.

Returns:

Sum along diagonal.

Return type:

cupy.ndarray

See also

scipy.sparse.spmatrix.trace()

transpose(axes=None, copy=False)[source]#

Reverses the dimensions of the sparse matrix.

trunc()[source]#

Elementwise trunc.

__eq__(other)[source]#

Return self==value.

__ne__(other)[source]#

Return self!=value.

__lt__(other)[source]#

Return self<value.

__le__(other)[source]#

Return self<=value.

__gt__(other)[source]#

Return self>value.

__ge__(other)[source]#

Return self>=value.

__nonzero__()[source]#
__bool__()[source]#

Attributes

A#

Dense ndarray representation of this matrix.

Deprecated since version 15.0: Use toarray() instead.

H#

Hermitian (conjugate) transpose of this matrix.

Deprecated since version 15.0: Use .T.conj() instead.

T#
device#

CUDA device on which this object resides.

dtype#

Data type of the matrix.

format = 'dia'#
imag#
mT#

Matrix transpose.

Equivalent to cupyx.scipy.sparse.matrix_transpose(). CuPy sparse types are 2-D only.

maxprint = 50#
ndim#
nnz#
real#
shape#

Shape of the matrix.

size#