Метод 1:
def subtract(A, B):
m = A.shape[0]
n = B.shape[0]
C = np.empty_like(A)
for i in range(m // n):
C[i*n : (i+1)*n] = A[i*n : (i+1)*n] - B
return C
Метод 2:
def subtract(A, B):
m = A.shape[0]
n = B.shape[0]
return A - np.tile(B, (m // n, 1))
Метод 3:
def subtract(A, B):
B_ = np.repeat(B, 5).reshape(B.size, -1).T.reshape(-1, B.shape[1])
return A - B_