Say you have two (or more) numpy
ndarrays
of equal size
(meaning they have equal number of elements) like:
A = np.array([[1],[2],[3]]) #Define a 3-element column vector
B = np.array([1,2,3]) #Define a 3-element row vector
Given that numpy's documentation advertises the *
and /
operators as "elementwise" between two ndarray
types why do the following:
AtimesB = A*B
AoverB = A/B
return:
array([[1, 2, 3],
[2, 4, 6],
[3, 6, 9]]) #AtimesB
array([[1. , 0.5 , 0.33333333],
[2. , 1. , 0.66666667],
[3. , 1.5 , 1. ]]) #AoverB
instead of:
array([1,4,9])
array([1,1,1])
To my knowledge, it is the @
operator which is meant to do matrix multiplications and np.divide
handles the matrix divisions. What am I missing here? Is this the way numpy
handles ambiguity regarding array shapes
?