Instead of using an array, you can use a second matrix with one column:
matrix = np.matrix(np.zeros((3,3)))
array = np.matrix([[1],[2],[3]])
matrix([[1],
[2],
[3]])
matrix + array
matrix([[ 1., 1., 1.],
[ 2., 2., 2.],
[ 3., 3., 3.]])
If you initially have an array, you can change it as follows:
a = np.asarray([1,2,3])
matrix + np.reshape(a, (3,1))
matrix([[ 1., 1., 1.],
[ 2., 2., 2.],
[ 3., 3., 3.]])
source
share