📜  numpy where - Python 代码示例

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

代码示例1
import numpy as np

# Return elements chosen from x or y depending on condition.
a = np.arange(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
single_where = np.where((a<5),-1,a) # [-1, -1, -1, -1, -1,  5,  6,  7,  8,  9]
multiple_where = np.where((a<5),-1,np.where((a>5),0,a)) # [-1, -1, -1, -1, -1,  5,  0,  0,  0,  0]