COO.from_iter¶
-
classmethod
COO.
from_iter
(x, shape=None, fill_value=None)[source]¶ Converts an iterable in certain formats to a
COO
array. See examples for details.Parameters: Returns: out – The output
COO
array.Return type: Examples
You can convert items of the format
[((i, j, k), value), ((i, j, k), value)]
toCOO
. Here, the first part represents the coordinate and the second part represents the value.>>> x = [((0, 0), 1), ((1, 1), 1)] >>> s = COO.from_iter(x) >>> s.todense() array([[1, 0], [0, 1]])
You can also have a similar format with a dictionary.
>>> x = {(0, 0): 1, (1, 1): 1} >>> s = COO.from_iter(x) >>> s.todense() array([[1, 0], [0, 1]])
The third supported format is
(data, (..., row, col))
.>>> x = ([1, 1], ([0, 1], [0, 1])) >>> s = COO.from_iter(x) >>> s.todense() array([[1, 0], [0, 1]])
You can also pass in a
collections.Iterator
object.>>> x = [((0, 0), 1), ((1, 1), 1)].__iter__() >>> s = COO.from_iter(x) >>> s.todense() array([[1, 0], [0, 1]])