cupy.sparse.spmatrix

class cupy.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:cupy.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:cupy.sparse.spmatrix
conj()[source]
conjugate()[source]
copy()[source]

Returns a copy of this matrix.

count_nonzero()[source]

Number of non-zero entries, equivalent to

diagonal()[source]

Returns the main diagonal of the matrix

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

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

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