📜  张量布尔掩码 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:38.839000             🧑  作者: Mango

代码示例1
# 1-D example
tensor = [0, 1, 2, 3]
mask = np.array([True, False, True, False])
boolean_mask(tensor, mask)  # [0, 2]

# 2-D example
tensor = [[1, 2], [3, 4], [5, 6]]
mask = np.array([True, False, True])
boolean_mask(tensor, mask)  # [[1, 2], [5, 6]]