cupyx.scipy.sparse.spmatrix#

class cupyx.scipy.sparse.spmatrix(maxprint=50)[source]#

Base class of all sparse matrixes.

See scipy.sparse.spmatrix

Methods

__len__()[source]#
__iter__()[source]#
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(t)[source]#

Casts the array to given data type.

Parameters:

t – Type specifier.

Returns:

A copy of the array with the given type and the same format.

Return type:

cupyx.scipy.sparse.spmatrix

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()[source]#

Number of non-zero entries, equivalent to

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

get(stream=None)[source]#

Return 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:

An array on host memory.

Return type:

scipy.sparse.spmatrix

getH()[source]#
get_shape()[source]#
getformat()[source]#
getmaxprint()[source]#
getnnz(axis=None)[source]#

Number of stored values, including explicit zeros.

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

Compute the arithmetic mean along the specified axis.

Returns the average of the matrix elements. The average is taken over all elements in the matrix by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.

Parameters:
  • {-2 (axis) – optional Axis along which the mean is computed. The default is to compute the mean of all elements in the matrix (i.e., axis = None).

  • -1 – optional Axis along which the mean is computed. The default is to compute the mean of all elements in the matrix (i.e., axis = None).

  • 0 – optional Axis along which the mean is computed. The default is to compute the mean of all elements in the matrix (i.e., axis = None).

  • 1 – optional Axis along which the mean is computed. The default is to compute the mean of all elements in the matrix (i.e., axis = None).

  • None} – optional Axis along which the mean is computed. The default is to compute the mean of all elements in the matrix (i.e., axis = None).

  • dtype (dtype) – optional Type to use in computing the mean. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.

  • out (cupy.ndarray) – optional Alternative output matrix in which to place the result. It must have the same shape as the expected output, but the type of the output values will be cast if necessary.

Returns:

Output array of means

Return type:

m (cupy.ndarray)

See also

scipy.sparse.spmatrix.mean()

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

Point-wise multiplication by another matrix

power(n, dtype=None)[source]#
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

set_shape(shape)[source]#
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).

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 comuted. 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()

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

Return a dense ndarray representation of this matrix.

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]#

Convert this matrix to Compressed Sparse Column format.

tocsr(copy=False)[source]#

Convert this matrix to Compressed Sparse Row format.

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

Return a dense matrix representation of this matrix.

todia(copy=False)[source]#

Convert this matrix to sparse DIAgonal format.

todok(copy=False)[source]#

Convert this matrix to Dictionary Of Keys format.

tolil(copy=False)[source]#

Convert this matrix to LInked List format.

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

Reverses the dimensions of the sparse matrix.

__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.

This property is equivalent to toarray() method.

H#
T#
device#

CUDA device on which this array resides.

ndim#
nnz#
shape#
size#