b_vals = data[:, (1)]
d_vals = data[:, (3)]
is_ok = np.zeros(np.max(b_vals) + 1, dtype=np.bool_)
np.logical_or.at(is_ok, b_vals, d_vals)
result = data[is_ok[b_vals]]
python filter 2d array by a chunk of data