vectorization : too many indices for array
问题 a=b=np.arange(9).reshape(3,3) i=np.arange(3) mask=a<i[:,None,None]+3 and b[np.where(mask[0])] >>>array([0, 1, 2]) b[np.where(mask[1])] >>>array([0, 1, 2, 3]) b[np.where(mask[2])] >>>array([0, 1, 2, 3, 4]) Now I wanna vectorize it and print them all together, and I try b[np.where(mask[i])] and b[np.where(mask[i[:,None,None]])] Both of them show IndexError: too many indices for array 回答1: In [165]: a Out[165]: array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) In [166]: mask Out[166]: array([[[ True,