mask = np.zeros((nrows, ncols), dtype=bool)
mask[np.arange(nrows)[:, (None)], B] = 1
mask[:, (~np.in1d(np.arange(mask.shape[1]), A))] = 0
R, C = np.where(mask.T)
out = np.split(C, np.flatnonzero(R[1:] > R[:-1]) + 1)
numpy - return index If value inside one of 3d array