# cupyx.scipy.sparse.spmatrix¶

class cupyx.scipy.sparse.spmatrix(maxprint=50)

Base class of all sparse matrixes.

Methods

__len__()
__iter__()
asformat(format)

Return this matrix in a given sparse format.

Parameters

format (str or None) – Format you need.

asfptype()

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)

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)

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)

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

Returns a copy of this matrix.

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

count_nonzero()

Number of non-zero entries, equivalent to

diagonal(k=0)

Returns the k-th diagonal of the matrix.

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

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

Returns

The k-th diagonal.

Return type

cupy.ndarray

dot(other)

Ordinary dot product

get(stream=None)

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()
get_shape()
getformat()
getmaxprint()
getnnz(axis=None)

Number of stored values, including explicit zeros.

maximum(other)
mean(axis=None, dtype=None, out=None)

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, -1, 0, 1, None} (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).

• 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)

minimum(other)
multiply(other)

Point-wise multiplication by another matrix

power(n, dtype=None)
reshape(shape, order='C')

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

set_shape(shape)
sum(axis=None, dtype=None, out=None)

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)

Return a dense ndarray representation of this matrix.

tobsr(blocksize=None, copy=False)

Convert this matrix to Block Sparse Row format.

tocoo(copy=False)

Convert this matrix to COOrdinate format.

tocsc(copy=False)

Convert this matrix to Compressed Sparse Column format.

tocsr(copy=False)

Convert this matrix to Compressed Sparse Row format.

todense(order=None, out=None)

Return a dense matrix representation of this matrix.

todia(copy=False)

Convert this matrix to sparse DIAgonal format.

todok(copy=False)

Convert this matrix to Dictionary Of Keys format.

tolil(copy=False)

Convert this matrix to LInked List format.

transpose(axes=None, copy=False)

Reverses the dimensions of the sparse matrix.

__eq__(other)

Return self==value.

__ne__(other)

Return self!=value.

__lt__(other)

Return self<value.

__le__(other)

Return self<=value.

__gt__(other)

Return self>value.

__ge__(other)

Return self>=value.

__nonzero__()
__bool__()

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