Textbook
For real vectors $v,w\in\mathbb R^d$ of the same dimension, the elementwise product is defined by $(v\odot w)_i=v_iw_i$. The result is a vector of the same dimension; coordinate products are not added.
For matrices of the same shape, the analogous rule is $(A\odot B)_{ij}=A_{ij}B_{ij}$. This differs from matrix multiplication, which matches inner dimensions and sums contributions. For the original vectors $v=(3,-4)^{\mathsf T}$ and $w=(1,2)^{\mathsf T}$, the result is $v\odot w=(3,-8)^{\mathsf T}$. Both notation and the library’s operator contract matter: an ordinary multiplication symbol in code does not always name the same operation.
Matching lengths are insufficient unless coordinates refer to corresponding positions in an agreed order. Reordering only one vector changes the paired factors and usually changes the result. For real coordinates the operation is commutative, since $v_iw_i=w_iv_i$ at every position. A zero factor erases only its matching coordinate; the other positions are computed independently.
Definitions and further reading: Mathematics for Machine Learning.
In plain language
An elementwise product resembles setting each audio channel’s volume separately: a level is multiplied by the coefficient with the same index. Zero silences a channel and one leaves its level unchanged. Results retain their separate positions instead of being added into one number. Exchanging coefficients can silence another microphone; the operation stays valid while the meeting suddenly becomes more interesting.
Example
The same illustrative vectors appear as in the dot-product example. Products 3 and −8 retain separate coordinates, which exposes the result’s type.
Elementwise Products: Keeping the Coordinates
Input vectors
The dimensions match: two coordinates each.
Step 1 of 3: Input vectors
Read all steps
Input vectors
The dimensions match: two coordinates each.
- v
- 3current−4current
- w
- 1current2current
Coordinate pairs
Each position produces its own product.
- v ⊙ w
- 3 × 1current−4 × 2current
Vector result
The values 3 and −8 stay separate instead of being added.
- v ⊙ w
- 3current−8current
The answer is checked coordinate by coordinate: the first is $3\cdot1=3$ and the second is $(-4)\cdot2=-8$. The second coordinate stays negative because exactly one of its factors is negative. The answer must have two entries, so the single number $-5$ exposes an unwanted summation. If the second coefficient were zero, the result would be $(3,0)^{\mathsf T}$: the first coordinate does not depend on its neighbor’s pair.
Related concepts: Dot products, Matrix multiplication.