numpy.iterable#
- numpy.iterable(y)[source]#
Check whether or not an object can be iterated over.
- Parameters:
- yobject
Input object.
- Returns:
- bbool
Return
Trueif the object has an iterator method or is asequence andFalseotherwise.
Notes
In most cases, the results of
np.iterable(obj)are consistent withisinstance(obj,collections.abc.Iterable). One notable exception isthe treatment of 0-dimensional arrays:>>>fromcollections.abcimportIterable>>>a=np.array(1.0)# 0-dimensional numpy array>>>isinstance(a,Iterable)True>>>np.iterable(a)False
Examples
>>>importnumpyasnp>>>np.iterable([1,2,3])True>>>np.iterable(2)False
On this page