flopscope.numpy.iterable
fnp.iterable(y)[flopscope source][numpy source]
Check whether or not an object can be iterated over.
Adapted from NumPy docs np.iterable
Cost
0
Flopscope Context
Return True if object is iterable.
Parameters
- y:object
Input object.
Returns
- b:bool
Return
Trueif the object has an iterator method or is a sequence andFalseotherwise.
Notes
In most cases, the results of flops.iterable(obj) are consistent with
isinstance(obj, collections.abc.Iterable). One notable exception is
the treatment of 0-dimensional arrays:
>>> from collections.abc import Iterable
>>> a = flops.array(1.0) # 0-dimensional numpy array
>>> isinstance(a, Iterable)
True
>>> flops.iterable(a)
FalseExamples
>>> import flopscope.numpy as fnp
>>> flops.iterable([1, 2, 3])
True
>>> flops.iterable(2)
False