def __array__(self, dtype=None):
"""NumPy array protocol; returns iterator values as an ndarray."""
if self._value is None:
# Call fromiter if we can; it is faster and avoids the extra
# copy, but doesn't support object types and requires a dtype.
if dtype is None or dtype.hasobject:
self._value = np.array(list(self._iterator), dtype)
else:
self._value = np.fromiter(self._iterator, dtype)
return self._value
评论列表
文章目录