dtlussier - 7 months ago 61

Python Question

What is the difference between an

`iterable`

`array_like`

`Numpy`

Both

`iterable`

`array_like`

I understand that in this context an

`array_like`

`Numpy`

`Numpy`

`array_like`

`iterable`

Answer

The term "array-like" is indeed only used in NumPy and refers to anything that can be passed as first parameter to `numpy.array()`

to create an array.

The term "iterable" is standard python terminology and refers to anything that can be iterated over (for example using `for x in iterable`

).

All array-like objects are iterable, but not all iterables are array-like -- for example you can't construct a NumPy array from a generator expression using `numpy.array()`

. (You would have to use `numpy.fromiter()`

instead. Nonetheless, a generator expression isn't an "array-like" in the terminology of the NumPy documentation.)

Source (Stackoverflow)