[ Web Proxy ]
URL:
Viewing: https://numpy.org/doc/stable/reference/generated/../c-api/../generated/numpy.iterable.html [Back]  [Original]

numpy.iterable — NumPy v2.5 Manual
Back to top
Search the docs ...:

numpy.iterable#

numpy.iterable(y)[source]#

Check whether or not an object can be iterated over.

Parameters:
yobject

Input object.

Returns:
bbool

Return True if the object has an iterator method or is a sequence and False otherwise.

Notes

In most cases, the results of np.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 = np.array(1.0)  # 0-dimensional numpy array
>>> isinstance(a, Iterable)
True
>>> np.iterable(a)
False

Examples

Try it in your browser!
>>> import numpy as np
>>> np.iterable([1, 2, 3])
True
>>> np.iterable(2)
False

Web Proxy Viewer  |  New URL  |  Original Page