术语:Python和Numpy - “iterable”与“array_like” [英] Terminology: Python and Numpy - `iterable` versus `array_like`
问题描述
在使用 iterable
和 array_like
对象之间有什么区别? > Numpy ?
What is the difference between an iterable
and an array_like
object in Python programs which use Numpy
?
iterable
和 array_like
经常在Python文档中看到,并且它们共享一些类似的属性。
Both iterable
and array_like
are often seen in Python documentation and they share some similar properties.
我知道在这种情况下, array_like
对象应该支持 Numpy
类型操作,如广播,但是 Numpy
数组区也是可迭代的。说出 array_like
是 iterable
的扩展名(或超级集合)?
I understand that in this context an array_like
object should support Numpy
type operations like broadcasting, however Numpy
arrays area also iterable. Is it correct to say that array_like
is an extension (or super-set?) of iterable
?
推荐答案
术语array-like确实只在NumPy中使用,并且是指可以作为第一个参数传递的任何内容 numpy.array()
创建一个数组。
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.
术语iterable是标准的python术语,指的是可以迭代的任何东西(例如使用对于x在可迭代的
)。
The term "iterable" is standard python terminology and refers to anything that can be iterated over (for example using for x in iterable
).
除了标量类型之外,大多数类似数组的对象是可迭代的。
Most array-like objects are iterable, with the exception of scalar types.
许多迭代不是数组的 - 例如,您不能使用 numpy.array()
从生成器表达式中构造NumPy数组。 (您将不得不使用 numpy.fromiter()
。然而,在NumPy文档的术语中,生成器表达式不是数组类。)
Many iterables are not 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.)
这篇关于术语:Python和Numpy - “iterable”与“array_like”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!