For example, suppose I have:
x = array([1, 2, 3])
y = array([4, 5, 6])
Standard "array multiplication" in python does z = x * y = array([4, 10, 18])
. In matlab, to get the same effect, you do *. IIRC.
What is this operation called, and which symbol is used to represent it?
You can use np. multiply to multiply two same-sized arrays together. This computes something called the Hadamard product. In the Hadamard product, the two inputs have the same shape, and the output contains the element-wise product of each of the input values.
What does Numpy Multiply Function do? The numpy multiply function calculates the product between the two numpy arrays. It calculates the product between the two arrays, say x1 and x2, element-wise.
Using Arithmetic Operators with Numpy You can perform arithmetic operations on these arrays. For example, if you add the arrays, the arithmetic operator will work element-wise. The output will be an array of the same dimension. You can run an arithmetic operation on the array with a scalar value.
It is the Hadamard product represented with an open circle: http://en.wikipedia.org/wiki/Matrix_multiplication#Hadamard_product
It seems to me you are after the expression S = sum_i( x_i * y_i)? That is called the inner product. From numpy documentation:
from numpy import *
x = array([1,2,3])
y = array([2,2,2])
inner(x,y) <-- Should give 1*2 + 2*2 + 3*2 = 12
The operation you have illustrated, and what you get with .* in matlab, is called a Schur/Hadamard product, often a small open circle is used as symbol. Since this is what you get with the normal '*' operator in numpy I doubt there is a separate Schur function.
Actually there are three different ways to multiply all the elements of two vectors.
The first one, the inner or dot product, returns a scalar.
The second one, the cross product, returns a vector.
The third one, the tensor product, returns a second-order tensor.
I'm sure you mean the first one, because it's familiar to most people, but I thought it'd be good to post this for the sake of completeness.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With