p**z 发帖数: 65 | 1 用 logic array 来 index 另一个 array:这两个 array 都必须是 numpy array。如
果用了 list,就会出错。例子:
>>> a = [1,2,3,4,5]
>>> b = [True, True, False, False, False]
>>> a[b]
Traceback (most recent call last):
File "", line 1, in
TypeError: list indices must be integers, not list
>>> a = np.array(a)
>>> a[b]
array([2, 2, 1, 1, 1])
>>> b = array(b)
>>> a[b]
array([1, 2]) |
|