Base.iterateElements

Base.iterateElements(order='point', only=None)

Iterate over each element in this object.

Provide an iterator which returns elements in the designated order. Optionally, the output of the iterator can be restricted to certain elements by the only function.

Parameters:
  • order (str) – ‘point’ or ‘feature’ to indicate how the iterator will access the elements in this object.

  • only (function, None) – If None, the default, all elements will be returned by the iterator. If a function, it must return True or False indicating whether the iterator should return the element.

Examples

>>> from nimble.match import nonZero, positive
>>> lst = [[0, 1, 2], [-2, -1, 0]]
>>> X = nimble.data(lst)
>>> list(X.iterateElements(order='point'))
[0, 1, 2, -2, -1, 0]
>>> list(X.iterateElements(order='feature'))
[0, -2, 1, -1, 2, 0]
>>> list(X.iterateElements(order='point', only=nonZero))
[1, 2, -2, -1]
>>> list(X.iterateElements(order='feature', only=positive))
[1, 2]

Keywords: loop, for, for each, iteration, while, all, values