cupyx.scipy.sparse.csc_matrix¶

class
cupyx.scipy.sparse.
csc_matrix
(arg1, shape=None, dtype=None, copy=False)¶ Compressed Sparse Column matrix.
Now it has only part of initializer formats:
csc_matrix(D)
D
is a rank2cupy.ndarray
.csc_matrix(S)
S
is another sparse matrix. It is equivalent toS.tocsc()
.csc_matrix((M, N), [dtype])
It constructs an empty matrix whose shape is
(M, N)
. Default dtype is float64.csc_matrix((data, indices, indptr))
All
data
,indices
andindptr
are onedimenaionalcupy.ndarray
.
 Parameters
arg1 – Arguments for the initializer.
shape (tuple) – Shape of a matrix. Its length must be two.
dtype – Data type. It must be an argument of
numpy.dtype
.copy (bool) – If
True
, copies of given arrays are always used.
See also
Methods

__getitem__
(key)¶

__setitem__
(key, x)¶

__len__
()¶

__iter__
()¶

arcsin
()¶ Elementwise arcsin.

arcsinh
()¶ Elementwise arcsinh.

arctan
()¶ Elementwise arctan.

arctanh
()¶ Elementwise arctanh.

argmax
(axis=None, out=None)¶ Returns indices of maximum elements along an axis.
Implicit zero elements are taken into account. If there are several maximum values, the index of the first occurrence is returned. If
NaN
values occur in the matrix, the output defaults to a zero entry for the row/column in which the NaN occurs. Parameters
axis (int) – {2, 1, 0, 1,
None
} (optional) Axis along which the argmax is computed. IfNone
(default), index of the maximum element in the flatten data is returned.out (None) – (optional) This argument is in the signature solely for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used.
 Returns
 Indices of maximum elements. If array,
its size along
axis
is 1.
 Return type
(cupy.narray or int)

argmin
(axis=None, out=None)¶ Returns indices of minimum elements along an axis.
Implicit zero elements are taken into account. If there are several minimum values, the index of the first occurrence is returned. If
NaN
values occur in the matrix, the output defaults to a zero entry for the row/column in which the NaN occurs. Parameters
axis (int) – {2, 1, 0, 1,
None
} (optional) Axis along which the argmin is computed. IfNone
(default), index of the minimum element in the flatten data is returned.out (None) – (optional) This argument is in the signature solely for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used.
 Returns
 Indices of minimum elements. If matrix,
its size along
axis
is 1.
 Return type
(cupy.narray or int)

asformat
(format)¶ Return this matrix in a given sparse format.

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

astype
(t)¶ Casts the array to given data type.
 Parameters
dtype – Type specifier.
 Returns
A copy of the array with a given type.

ceil
()¶ Elementwise ceil.

conj
(copy=True)¶ Elementwise complex conjugation.
If the matrix is of noncomplex 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 elementwise complex conjugate.
 Return type

conjugate
(copy=True)¶ Elementwise complex conjugation.
If the matrix is of noncomplex 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 elementwise complex conjugate.
 Return type

copy
()¶ Returns a copy of this matrix.
No data/indices will be shared between the returned value and current matrix.

count_nonzero
()¶ Returns number of nonzero entries.
Note
This method counts the actual number of nonzero entories, which does not include explicit zero entries. Instead
nnz
returns the number of entries including explicit zeros. Returns
Number of nonzero entries.

deg2rad
()¶ Elementwise deg2rad.

diagonal
(k=0)¶ Returns the kth 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 kth diagonal.
 Return type

dot
(other)¶ Ordinary dot product

eliminate_zeros
()¶ Removes zero entories in place.

expm1
()¶ Elementwise expm1.

floor
()¶ Elementwise floor.

get
(stream=None)¶ Returns a copy of the array on host memory.
Warning
You need to install SciPy to use this method.
 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

getH
()¶

getcol
(i)¶ Returns a copy of column i of the matrix, as a (m x 1) CSC matrix (column vector).
 Parameters
i (integer) – Column
 Returns
Sparse matrix with single column
 Return type

getformat
()¶

getmaxprint
()¶

getnnz
(axis=None)¶ Returns the number of stored values, including explicit zeros.
 Parameters
axis – Not supported yet.
 Returns
The number of stored values.
 Return type

getrow
(i)¶ Returns a copy of row i of the matrix, as a (1 x n) CSR matrix (row vector).
 Parameters
i (integer) – Row
 Returns
Sparse matrix with single row
 Return type

log1p
()¶ Elementwise log1p.

max
(axis=None, out=None, *, explicit=False)¶ Returns the maximum of the matrix or maximum along an axis.
 Parameters
axis (int) – {2, 1, 0, 1,
None
} (optional) Axis along which the sum is computed. The default is to compute the maximum over all the matrix elements, returning a scalar (i.e.axis
=None
).out (None) – (optional) This argument is in the signature solely for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used.
explicit (bool) – Return the maximum value explicitly specified and ignore all implicit zero entries. If the dimension has no explicit values, a zero is then returned to indicate that it is the only implicit value. This parameter is experimental and may change in the future.
 Returns
 Maximum of
a
. Ifaxis
is None
, the result is a scalar value. Ifaxis
is given, the result is an array of dimensiona.ndim  1
. This differs from numpy for computational efficiency.
 Maximum of
 Return type
(cupy.ndarray or float)
See also
min : The minimum value of a sparse matrix along a given axis.
See also
numpy.matrix.max : NumPy’s implementation of
max
for matrices

maximum
(other)¶

mean
(axis=None, dtype=None, out=None)¶ Compute the arithmetic mean along the specified axis.
 Parameters
axis (int or
None
) – Axis along which the sum is computed. If it isNone
, it computes the average of all the elements. Select from{None, 0, 1, 2, 1}
. Returns
Summed array.
 Return type
See also

min
(axis=None, out=None, *, explicit=False)¶ Returns the minimum of the matrix or maximum along an axis.
 Parameters
axis (int) – {2, 1, 0, 1,
None
} (optional) Axis along which the sum is computed. The default is to compute the minimum over all the matrix elements, returning a scalar (i.e.axis
=None
).out (None) – (optional) This argument is in the signature solely for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used.
explicit (bool) – Return the minimum value explicitly specified and ignore all implicit zero entries. If the dimension has no explicit values, a zero is then returned to indicate that it is the only implicit value. This parameter is experimental and may change in the future.
 Returns
 Minimum of
a
. Ifaxis
is None, the result is a scalar value. If
axis
is given, the result is an array of dimensiona.ndim  1
. This differs from numpy for computational efficiency.
 Minimum of
 Return type
(cupy.ndarray or float)
See also
max : The maximum value of a sparse matrix along a given axis.
See also
numpy.matrix.min : NumPy’s implementation of ‘min’ for matrices

minimum
(other)¶

multiply
(other)¶ Pointwise multiplication by another matrix

power
(n, dtype=None)¶ Elementwise power function.
 Parameters
n – Exponent.
dtype – Type specifier.

rad2deg
()¶ Elementwise rad2deg.

reshape
(shape, order='C')¶ Gives a new shape to a sparse matrix without changing its data.

rint
()¶ Elementwise rint.

set_shape
(shape)¶

sign
()¶ Elementwise sign.

sin
()¶ Elementwise sin.

sinh
()¶ Elementwise sinh.

sort_indices
()¶ Sorts the indices of this matrix in place.
Warning
Calling this function might synchronize the device.

sorted_indices
()¶ Return a copy of this matrix with sorted indices
Warning
Calling this function might synchronize the device.

sqrt
()¶ Elementwise sqrt.

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 isNone
, 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
See also

sum_duplicates
()¶ Eliminate duplicate matrix entries by adding them together.
Note
This is an in place operation.
Warning
Calling this function might synchronize the device.

tan
()¶ Elementwise tan.

tanh
()¶ Elementwise tanh.

toarray
(order=None, out=None)¶ Returns a dense matrix representing the same value.
 Parameters
order ({'C', 'F', None}) – Whether to store data in C (rowmajor) order or F (columnmajor) order. Default is Corder.
out – Not supported.
 Returns
Dense array representing the same matrix.
 Return type
See also

tobsr
(blocksize=None, copy=False)¶ Convert this matrix to Block Sparse Row format.

tocoo
(copy=False)¶ Converts the matrix to COOdinate format.
 Parameters
copy (bool) – If
False
, it shares data arrays as much as possible. Returns
Converted matrix.
 Return type

tocsc
(copy=None)¶ Converts the matrix to Compressed Sparse Column format.
 Parameters
copy (bool) – If
False
, the method returns itself. Otherwise it makes a copy of the matrix. Returns
Converted matrix.
 Return type

tocsr
(copy=False)¶ 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 csr to csc conversion. Returns
Converted matrix.
 Return type

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)¶ Returns a transpose matrix.
 Parameters
axes – This option is not supported.
copy (bool) – If
True
, a returned matrix shares no data. Otherwise, it shared data arrays as much as possible.
 Returns
Transpose matrix.
 Return type

trunc
()¶ Elementwise trunc.

__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

H
¶

T
¶

device
¶ CUDA device on which this array resides.

dtype
¶ Data type of the matrix.

format
= 'csc'¶

has_canonical_format
¶ Determine whether the matrix has sorted indices and no duplicates.
 Returns
bool:
True
if the above applies, otherwiseFalse
.
Note
has_canonical_format
implieshas_sorted_indices
, so if the latter flag isFalse
, so will the former be; if the former is foundTrue
, the latter flag is also set.Warning
Getting this property might synchronize the device.

has_sorted_indices
¶ Determine whether the matrix has sorted indices.
 Returns
 bool:
True
if the indices of the matrix are in sorted order, otherwiseFalse
.
Warning
Getting this property might synchronize the device.

ndim
¶

nnz
¶

shape
¶

size
¶