asarray

sparse.asarray(obj, /, *, dtype=None, format='coo', device=None, copy=False)[source]

Convert the input to a sparse array.

Parameters:
  • obj (array_like) – Object to be converted to an array.

  • dtype (dtype, optional) – Output array data type.

  • format (str, optional) – Output array sparse format.

  • device (str, optional) – Device on which to place the created array.

  • copy (bool, optional) – Boolean indicating whether or not to copy the input.

Returns:

out – Sparse or 0-D array containing the data from obj.

Return type:

Union[SparseArray, numpy.ndarray]

Examples

>>> x = np.eye(8, dtype="i8")
>>> sparse.asarray(x, format="COO")
<COO: shape=(8, 8), dtype=int64, nnz=8, fill_value=0>