COO.from_numpy

classmethod COO.from_numpy(x, fill_value=None, idx_dtype=None)[source]

Convert the given numpy.ndarray to a COO object.

Parameters:
  • x (np.ndarray) – The dense array to convert.

  • fill_value (scalar) – The fill value of the constructed COO array. Zero if unspecified.

Returns:

The converted COO array.

Return type:

COO

Examples

>>> x = np.eye(5)
>>> s = COO.from_numpy(x)
>>> s
<COO: shape=(5, 5), dtype=float64, nnz=5, fill_value=0.0>
>>> x[x == 0] = np.nan
>>> COO.from_numpy(x, fill_value=np.nan)
<COO: shape=(5, 5), dtype=float64, nnz=5, fill_value=nan>