COO.from_numpy¶
-
classmethod
COO.
from_numpy
(x, fill_value=None)[source]¶ Convert the given
numpy.ndarray
to aCOO
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: 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>