If you have an (m,n) matrix A and apply operations like sub(-), add(+), mul(*) or div(/) by a vector v the shape of v will be grow vertically or horizontally like:
(1,n) -> (m,n)
(m,1) -> (m,n)
v=[1,2,3,4],x=100
v+x= vector + escalar
Python turns the 100 into a vector with the same shape of v, like:
v=[1,2,3,4]+[100,100,100,100]
v=[101,102,103,104]
v1=[[1,2,3],[4,5,6]] + v2=[100,200,300]
v2 will become like: [[100,200,300],[100,200,300]]
v1=[[1,2,3],[4,5,6]] + v2=[[100],[200]]
v2 will become like: [[100,100,100],[200,200,200]]
import numpy as np;
A = np.array(
[[56.0, 0.0, 4.4, 68.0],
[1.2, 104.0, 52.0, 8.0],
[1.8, 135.0, 99.0, 0.9]]
)
print(A)
[[ 56. 0. 4.4 68. ] [ 1.2 104. 52. 8. ] [ 1.8 135. 99. 0.9]]
sum = A.sum(axis = 0)
sum
array([ 59. , 239. , 155.4, 76.9])
A/sum
array([[0.94915254, 0. , 0.02831403, 0.88426528], [0.02033898, 0.43514644, 0.33462033, 0.10403121], [0.03050847, 0.56485356, 0.63706564, 0.01170351]])