The problem is that you are concatenating the arrays and scalars with
np.array and applying the sum for a given axis of it. If I understand your ambitions correctly, I recommend you to perform the sum operations for each array, and later join the results into a numpy array:
A = np.array([np.sum(arr) for arr in [x**2, x, x, n]]).reshape((2,2)) B = np.array([np.sum(arr) for arr in [x*y , y]]).reshape((2,1))
The reshapes are necessary to transform
B into a 2×2 and 2×1 arrays.
CLICK HERE to find out more related problems solutions.