asarray
- sparse.asarray(obj, /, *, dtype=None, format='coo', backend='pydata', device=None, copy=False)[source]
Convert the input to a sparse array. :param obj: Object to be converted to an array. :type obj: array_like :param dtype: Output array data type. :type dtype: dtype, optional :param format: Output array sparse format. :type format: str, optional :param backend: Backend for the output array. :type backend: str, optional :param device: Device on which to place the created array. :type device: str, optional :param copy: Boolean indicating whether or not to copy the input. :type copy: bool, optional
- 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>