给定一个 2D numpy 数组,即;
import numpy as np
data = np.array([
[11,12,13],
[21,22,23],
[31,32,33],
[41,42,43],
])
我需要根据所需行和列的两个掩码向量修改一个子数组;
rows = np.array([False, False, True, True], dtype=bool)
cols = np.array([True, True, False], dtype=bool)
这样,即;
print data
#[[11,12,13],
# [21,22,23],
# [0,0,33],
# [0,0,43]]