執行 ❯
擁有你自己的 Python 伺服器
×
更改方向
更改主題,深色/淺色
前往 Spaces
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7]) # Create an empty list filter_arr = [] # go through each element in arr for element in arr: # if the element is completely divisble by 2, set the value to True, otherwise False if element % 2 == 0: filter_arr.append(True) else: filter_arr.append(False) newarr = arr[filter_arr] print(filter_arr) print(newarr)
[假, 真, 假, 真, 假, 真, 假]
[2 4 6]