numpy.iterable#
- numpy.iterable(y)[原始碼]#
檢查物件是否可迭代。
- 參數:
- y物件
輸入物件。
- 回傳值:
- b布林值
如果物件具有迭代器方法或是序列,則回傳
True
,否則回傳False
。
註解
在大多數情況下,
np.iterable(obj)
的結果與isinstance(obj, collections.abc.Iterable)
一致。一個值得注意的例外是 0 維陣列的處理方式>>> from collections.abc import Iterable >>> a = np.array(1.0) # 0-dimensional numpy array >>> isinstance(a, Iterable) True >>> np.iterable(a) False
範例
>>> import numpy as np >>> np.iterable([1, 2, 3]) True >>> np.iterable(2) False