cupy.sparse.coo_matrix¶
-
class
cupy.sparse.
coo_matrix
(arg1, shape=None, dtype=None, copy=False)[source]¶ COOrdinate format sparse matrix.
Now it has only one initializer format below:
coo_matrix(S)
S
is another sparse matrix. It is equivalent toS.tocoo()
.coo_matrix((M, N), [dtype])
- It constructs an empty matrix whose shape is
(M, N)
. Default dtype is float64. coo_matrix((data, (row, col))
- All
data
,row
andcol
are one-dimenaionalcupy.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 data are always used.
See also
Methods
-
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: dtype – Type specifier. Returns: A copy of the array with a given type.
-
count_nonzero
()[source]¶ Returns number of non-zero entries.
Note
This method counts the actual number of non-zero entories, which does not include explicit zero entries. Instead
nnz
returns the number of entries including explicit zeros.Returns: Number of non-zero entries.
-
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.coo_matrix
-
get_shape
()[source]¶ Returns the shape of the matrix.
Returns: Shape of the matrix. Return type: tuple
-
power
(n, dtype=None)[source]¶ Elementwise power function.
Parameters: - n – Exponent.
- dtype – Type specifier.
-
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 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
- axis (int or
-
toarray
(order=None, out=None)[source]¶ Returns a dense matrix representing the same value.
Parameters: - order (str) – Not supported.
- out – Not supported.
Returns: Dense array representing the same value.
Return type: See also
-
tocoo
(copy=False)[source]¶ Converts the matrix to COOdinate format.
Parameters: copy (bool) – If False
, it shares data arrays as much as possible.Returns: Converted matrix. Return type: cupy.sparse.coo_matrix
-
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 coo to csc conversion.Returns: Converted matrix. Return type: cupy.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 coo to csr conversion.Returns: Converted matrix. Return type: cupy.sparse.csr_matrix
-
transpose
(axes=None, copy=False)[source]¶ 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:
Attributes
-
H
¶
-
T
¶
-
device
¶ CUDA device on which this array resides.
-
dtype
¶ Data type of the matrix.
-
format
= 'coo'¶
-
has_canonical_format
¶
-
ndim
¶
-
nnz
¶
-
shape
¶
-
size
¶