📜  迭代python代码示例

📅  最后修改于: 2022-03-11 14:45:07.280000             🧑  作者: Mango

代码示例4
import numpy as np
# With array cycling
arr = np.array([1,2,3,4,5,6,7,8,9])

for i in range(len(arr)):
 # logic with iterator use (current logic replaces even numbers with zero)
    if arr[i] % 2 == 0: arr[i] = 0

print(arr)
# Output: [1, 0, 3, 0, 5, 0, 7, 0 , 9]