我如何才能有效地更改代码,使其在不需要许多编程循环的情况下,从3维的2D数值数组A中减go 1D数值数组B,从而得到C[0,i,j]=A[i,j]-B[0]和C[1,i,j]=A[i,j]-B[1].
import numpy as np
B=np.array([1, 100])
A=np.arange(4*5).reshape(4,5)
#C=A-B this will not work as A and B have different number of columns
#A=array([[ 0, 1, 2, 3, 4],
# [ 5, 6, 7, 8, 9],
# [10, 11, 12, 13, 14],
# [15, 16, 17, 18, 19]])