Terminology: Python and Numpy - `iterable` versus `array_like`

后端 未结 2 1137
情书的邮戳
情书的邮戳 2020-12-15 18:08

What is the difference between an iterable and an array_like object in Python programs which use Numpy?

Both iterable

2条回答
  •  北海茫月
    2020-12-15 18:58

    While the first part of the Sven's answer is correct, I would like to add that array-like objects should not necessarily be iterable.

    For example, in my particular situation I was interested in using numpy.rint() function that accepts array-like objects with scalars of type int. They are not iterable, but they are accepted. You can also pass ints to numpy.array(), so they are array-like.

    Here is the confirmation from the "NumPy-Discussion" mailing list: https://mail.scipy.org/pipermail/numpy-discussion/2016-November/076224.html

提交回复
热议问题