When I multiply two numpy arrays of sizes (nxn) * (nx 1), I get a matrix of size (nxn). Following the rules of normal matrix multiplication, a vector (nx 1) is expected, but I just can't find any information on how to do this in the Python Numpy module.
The fact is that I do not want to implement it manually in order to maintain the speed of the program.
A sample code is shown below:
a = np.array([[ 5, 1 ,3], [ 1, 1 ,1], [ 1, 2 ,1]]) b = np.array([1, 2, 3]) print a*b >> [[5 2 9] [1 2 3] [1 4 3]]
I want to:
print a*b >> [16 6 8]
python arrays numpy vector matrix
user3272574 Feb 04 '14 at 20:43 2014-02-04 20:43
source share