The key is to reshape the vector of size (3,) to (3,1): divide each row by an element or (1,3): divide each column by an element. As data.shape does not correspond to vector.shape, NumPy automatically expands vector's shape to (3,3) and performs division, element-wise.
In[1]: data/vector.reshape(-1,1)
Out[1]:
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
In[2]: data/vector.reshape(1,-1)
Out[2]:
array([[1. , 0.5 , 0.33333333],
[2. , 1. , 0.66666667],
[3. , 1.5 , 1. ]])
Similar:
x = np.arange(9).reshape(3,3)
x
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
x/np.sum(x, axis=0, keepdims=True)
array([[0. , 0.08333333, 0.13333333],
[0.33333333, 0.33333333, 0.33333333],
[0.66666667, 0.58333333, 0.53333333]])
x/np.sum(x, axis=1, keepdims=True)
array([[0. , 0.33333333, 0.66666667],
[0.25 , 0.33333333, 0.41666667],
[0.28571429, 0.33333333, 0.38095238]])
print(np.sum(x, axis=0).shape)
print(np.sum(x, axis=1).shape)
print(np.sum(x, axis=0, keepdims=True).shape)
print(np.sum(x, axis=1, keepdims=True).shape)
(3,)
(3,)
(1, 3)
(3, 1)