HOME

TheInfoList



OR:

In
mathematics Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
, the Hadamard product (also known as the element-wise product, entrywise product or Schur product) is a
binary operation In mathematics, a binary operation or dyadic operation is a rule for combining two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two. More specifically, a binary operation ...
that takes in two
matrices Matrix (: matrices or matrixes) or MATRIX may refer to: Science and mathematics * Matrix (mathematics), a rectangular array of numbers, symbols or expressions * Matrix (logic), part of a formula in prenex normal form * Matrix (biology), the ...
of the same dimensions and returns a matrix of the multiplied corresponding elements. This operation can be thought as a "naive matrix multiplication" and is different from the
matrix product In mathematics, specifically in linear algebra, matrix multiplication is a binary operation that produces a matrix from two matrices. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the s ...
. It is attributed to, and named after, either French mathematician
Jacques Hadamard Jacques Salomon Hadamard (; 8 December 1865 – 17 October 1963) was a French mathematician who made major contributions in number theory, complex analysis, differential geometry, and partial differential equations. Biography The son of a tea ...
or German mathematician
Issai Schur Issai Schur (10 January 1875 – 10 January 1941) was a Russian mathematician who worked in Germany for most of his life. He studied at the Humboldt University of Berlin, University of Berlin. He obtained his doctorate in 1901, became lecturer i ...
. The Hadamard product is
associative In mathematics, the associative property is a property of some binary operations that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement for express ...
and distributive. Unlike the matrix product, it is also
commutative In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Perhaps most familiar as a pr ...
.


Definition

For two matrices and of the same dimension , the Hadamard product A \odot B (sometimes A \circ B) is a matrix of the same dimension as the operands, with elements given by :(A \odot B)_ = (A)_ (B)_. For matrices of different dimensions ( and , where or ), the Hadamard product is undefined. An example of the Hadamard product for two arbitrary 2 × 3 matrices: : \begin 2 & 3 & 1 \\ 0 & 8 & -2 \end \circ \begin 3 & 1 & 4 \\ 7 & 9 & 5 \end = \begin 2 \times 3 & 3 \times 1 & 1 \times 4 \\ 0 \times 7 & 8 \times 9 & -2 \times 5 \end = \begin 6 & 3 & 4 \\ 0 & 72 & -10 \end.


Properties

* The Hadamard product is
commutative In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Perhaps most familiar as a pr ...
(when working with a commutative ring),
associative In mathematics, the associative property is a property of some binary operations that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement for express ...
and distributive over addition. That is, if ''A'', ''B'', and ''C'' are matrices of the same size, and ''k'' is a scalar: \begin A \odot B &= B \odot A, \\ A \odot (B \odot C) &= (A \odot B) \odot C, \\ A \odot (B + C) &= A \odot B + A \odot C, \\ (kA) \odot B &= A \odot (kB) = k(A \odot B), \\ A \odot 0 &= 0 \odot A = 0. \end * The identity matrix under Hadamard multiplication of two matrices is an matrix where all elements are equal to 1. This is different from the
identity matrix In linear algebra, the identity matrix of size n is the n\times n square matrix with ones on the main diagonal and zeros elsewhere. It has unique properties, for example when the identity matrix represents a geometric transformation, the obje ...
under regular matrix multiplication, where only the elements of the main diagonal are equal to 1. Furthermore, a matrix has an inverse under Hadamard multiplication if and only if all of the elements are invertible, or equivalently over a field, if and only if none of the elements are equal to zero. * For vectors and and corresponding diagonal matrices and with these vectors as their main diagonals, the following identity holds: \mathbf^* (A \odot B)\mathbf = \operatorname\left(_\mathbf^* A _\mathbf ^\mathsf\right), where denotes the
conjugate transpose In mathematics, the conjugate transpose, also known as the Hermitian transpose, of an m \times n complex matrix \mathbf is an n \times m matrix obtained by transposing \mathbf and applying complex conjugation to each entry (the complex conjugate ...
of . In particular, using vectors of ones, this shows that the sum of all elements in the Hadamard product is the
trace Trace may refer to: Arts and entertainment Music * ''Trace'' (Son Volt album), 1995 * ''Trace'' (Died Pretty album), 1993 * Trace (band), a Dutch progressive rock band * ''The Trace'' (album), by Nell Other uses in arts and entertainment * ...
of where superscript T denotes the
matrix transpose In linear algebra, the transpose of a matrix is an operator which flips a matrix over its diagonal; that is, it switches the row and column indices of the matrix by producing another matrix, often denoted by (among other notations). The tr ...
, that is, \operatorname\left(AB^\right) = \mathbf^\mathsf\left(A\odot B\right)\mathbf. A related result for square and , is that the row-sums of their Hadamard product are the diagonal elements of : \sum_i (A \odot B)_ = \left(B^\mathsf A\right)_ = \left(AB^\mathsf\right)_. Similarly, (\mathbf\mathbf^*) \odot A = D_\mathbf A D_\mathbf^*. Furthermore, a Hadamard matrix–vector product can be expressed as (A \odot B) \mathbf = \operatorname(A D_\mathbf B^\mathsf), where \operatorname(M) is the vector formed from the diagonals of matrix . * The Hadamard product is a principal
submatrix In mathematics, a matrix (: matrices) is a rectangular array or table of numbers, symbols, or expressions, with elements or entries arranged in rows and columns, which is used to represent a mathematical object or property of such an object. ...
of the
Kronecker product In mathematics, the Kronecker product, sometimes denoted by ⊗, is an operation on two matrices of arbitrary size resulting in a block matrix. It is a specialization of the tensor product (which is denoted by the same symbol) from vector ...
. * The Hadamard product satisfies the rank inequality \operatorname(A \odot B) \leq \operatorname(A) \operatorname(B). * If and are positive-definite matrices, then the following inequality involving the Hadamard product holds: \prod_^n \lambda_i(A \odot B) \ge \prod_^n \lambda_i(A B),\quad k = 1, \ldots, n, where is the th largest
eigenvalue In linear algebra, an eigenvector ( ) or characteristic vector is a vector that has its direction unchanged (or reversed) by a given linear transformation. More precisely, an eigenvector \mathbf v of a linear transformation T is scaled by a ...
of . * If and are
diagonal matrices In linear algebra, a diagonal matrix is a matrix in which the entries outside the main diagonal are all zero; the term usually refers to square matrices. Elements of the main diagonal can either be zero or nonzero. An example of a 2×2 diagona ...
, then \begin D (A \odot B) E &= (D A E) \odot B = (D A) \odot (B E) \\ &= (AE) \odot (D B) = A \odot (D B E). \end * The Hadamard product of two vectors \mathbf a and \mathbf b is the same as matrix multiplication of the corresponding
diagonal matrix In linear algebra, a diagonal matrix is a matrix in which the entries outside the main diagonal are all zero; the term usually refers to square matrices. Elements of the main diagonal can either be zero or nonzero. An example of a 2×2 diagon ...
of one vector by the other vector: \mathbf a \odot \mathbf b = D_\mathbf \mathbf b = D_\mathbf \mathbf a. * The \operatorname operator transforming a vector to a diagonal matrix may be expressed using the Hadamard product as \operatorname(\mathbf) = (\mathbf \mathbf^T) \odot I, where \mathbf is a constant vector with elements 1, and I is the
identity matrix In linear algebra, the identity matrix of size n is the n\times n square matrix with ones on the main diagonal and zeros elsewhere. It has unique properties, for example when the identity matrix represents a geometric transformation, the obje ...
.


The mixed-product property

The Hadamard product obeys certain relationships with other matrix product operators. * If \otimes is the
Kronecker product In mathematics, the Kronecker product, sometimes denoted by ⊗, is an operation on two matrices of arbitrary size resulting in a block matrix. It is a specialization of the tensor product (which is denoted by the same symbol) from vector ...
, assuming A has the same dimensions as C and B as D, then (A \otimes B) \odot (C \otimes D) = (A \odot C) \otimes (B \odot D) . * If \bull is the face-splitting product, then (A \bull B) \odot (C \bull D) = (A \odot C) \bull (B \odot D). * If \ast is the column-wise
Khatri–Rao product In mathematics, the Khatri–Rao product or block Kronecker product of two partitioned matrix, partitioned matrices \mathbf and \mathbf is defined as : \mathbf \ast \mathbf = \left(\mathbf_ \otimes \mathbf_\right)_ in which the ''ij''-th block is ...
, then (A \bull B)(C \ast D) = (A C) \odot (B D).


Schur product theorem

The Hadamard product of two positive-semidefinite matrices is positive-semidefinite. This is known as the Schur product theorem, after Russian mathematician
Issai Schur Issai Schur (10 January 1875 – 10 January 1941) was a Russian mathematician who worked in Germany for most of his life. He studied at the Humboldt University of Berlin, University of Berlin. He obtained his doctorate in 1901, became lecturer i ...
. For two positive-semidefinite matrices and , it is also known that the
determinant In mathematics, the determinant is a Scalar (mathematics), scalar-valued function (mathematics), function of the entries of a square matrix. The determinant of a matrix is commonly denoted , , or . Its value characterizes some properties of the ...
of their Hadamard product is greater than or equal to the product of their respective determinants:\det( \odot ) \ge \det() \det().


Analogous operations

Other Hadamard operations are also seen in the mathematical literature, namely the ' and ' (which are in effect the same thing because of fractional indices), defined for a matrix such that: For \begin &= ^ \\ B_ &= ^2 \end and for \begin &= ^ \\ B_ &= ^\frac12 \end The ' reads: \begin &= ^ \\ B_ &= ^ \end A ' is defined as: \begin &= \oslash \\ C_ &= \frac \end


In programming languages

Most scientific or numerical
programming languages A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their syntax (form) and semantics (meaning), usually defined by a formal language. Languages usually provide features ...
include the Hadamard product, under various names. In
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementat ...
, the Hadamard product is expressed as "dot multiply": a .* b, or the function call: times(a, b). It also has analogous dot operators which include, for example, the operators a .^ b and a ./ b. Because of this mechanism, it is possible to reserve * and ^ for matrix multiplication and matrix exponentials, respectively. The programming language Julia has similar syntax as MATLAB, where Hadamard multiplication is called ''broadcast multiplication'' and also denoted with a .* b, and other operators are analogously defined element-wise, for example Hadamard powers use a .^ b. But unlike MATLAB, in Julia this "dot" syntax is generalized with a generic ''broadcasting operator .'' which can apply any function element-wise. This includes both binary operators (such as the aforementioned multiplication and exponentiation, as well as any other binary operator such as the Kronecker product), and also unary operators such as ! and . Thus, any function in
prefix notation Polish notation (PN), also known as normal Polish notation (NPN), Łukasiewicz notation, Warsaw notation, Polish prefix notation, Eastern Notation or simply prefix notation, is a mathematical notation in which operators ''precede'' their oper ...
f can be applied as f.(x). Python does not have built-in array support, leading to inconsistent/conflicting notations. The
NumPy NumPy (pronounced ) is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. The predeces ...
numerical library interprets a*b or a.multiply(b) as the Hadamard product, and uses a@b or a.matmul(b) for the matrix product. With the
SymPy SymPy is an open-source Python library for symbolic computation. It provides computer algebra capabilities either as a standalone application, as a library to other applications, or live on the web as SymPy Live or SymPy Gamma. SymPy is simple ...
symbolic library, multiplication of objects as either a*b or a@b will produce the matrix product. The Hadamard product can be obtained with the method call a.multiply_elementwise(b). Some Python packages include support for Hadamard powers using methods like np.power(a, b), or the Pandas method a.pow(b). In C++, the
Eigen Eigen may refer to: People with the given name *, Japanese sport shooter *, Japanese professional wrestler * Frauke Eigen (born 1969) German photographer, photojournalist and artist * Manfred Eigen (1927–2019), German biophysicist * Michael Ei ...
library provides a cwiseProduct member function for the class (a.cwiseProduct(b)), while the
Armadillo Armadillos () are New World placental mammals in the order (biology), order Cingulata. They form part of the superorder Xenarthra, along with the anteaters and sloths. 21 extant species of armadillo have been described, some of which are dis ...
library uses the operator % to make compact expressions (a % b; a * b is a matrix product). In
GAUSS Johann Carl Friedrich Gauss (; ; ; 30 April 177723 February 1855) was a German mathematician, astronomer, Geodesy, geodesist, and physicist, who contributed to many fields in mathematics and science. He was director of the Göttingen Observat ...
, and HP Prime, the operation is known as ''array multiplication.'' In Fortran, R, APL, J and
Wolfram Language The Wolfram Language ( ) is a proprietary, very high-level multi-paradigm programming language developed by Wolfram Research. It emphasizes symbolic computation, functional programming, and rule-based programming and can employ arbitrary stru ...
(
Mathematica Wolfram (previously known as Mathematica and Wolfram Mathematica) is a software system with built-in libraries for several areas of technical computing that allows machine learning, statistics, symbolic computation, data manipulation, network ...
), the multiplication operator * or × apply the Hadamard product, whereas the matrix product is written using matmul, %*%, +.×, +/ .* and ., respectively. The R packag
matrixcalc
introduces the function hadamard.prod() for Hadamard Product of numeric matrices or vectors.


Applications

The Hadamard product appears in
lossy compression In information technology, lossy compression or irreversible compression is the class of data compression methods that uses inexact approximations and partial data discarding to represent the content. These techniques are used to reduce data size ...
algorithms such as
JPEG JPEG ( , short for Joint Photographic Experts Group and sometimes retroactively referred to as JPEG 1) is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degr ...
. The decoding step involves an entry-for-entry product, in other words the Hadamard product. In
image processing An image or picture is a visual representation. An image can be two-dimensional, such as a drawing, painting, or photograph, or three-dimensional, such as a carving or sculpture. Images may be displayed through other media, including a pr ...
, the Hadamard operator can be used for enhancing, suppressing or masking image regions. One matrix represents the original image, the other acts as weight or masking matrix. It is used in the
machine learning Machine learning (ML) is a field of study in artificial intelligence concerned with the development and study of Computational statistics, statistical algorithms that can learn from data and generalise to unseen data, and thus perform Task ( ...
literature, for example, to describe the architecture of recurrent neural networks as GRUs or LSTMs. It is also used to study the statistical properties of random vectors and matrices.


The penetrating face product

According to the definition of V. Slyusar the penetrating face product of the ''p''×''g'' matrix and ''n''-dimensional matrix (''n'' > 1) with ''p''×''g'' blocks ( = _n) is a matrix of size of the form:
circ Circ or CIRC may refer to: * Čirč, a village and municipality in northern Slovakia * Circ (duo), an American music duo * Cook Islands Round Cup, top division association football league in the Cook Islands Commercial * China Insurance Regulato ...
= \left begin \circ _1 & \circ _2 & \cdots & \circ _n \end\right


Example

If = \begin 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end,\quad = \left begin _1 & _2 & _3 \end\right= \left begin 1 & 4 & 7 & 2 & 8 & 14 & 3 & 12 & 21 \\ 8 & 20 & 5 & 10 & 25 & 40 & 12 & 30 & 6 \\ 2 & 8 & 3 & 2 & 4 & 2 & 7 & 3 & 9 \end\right then
circ Circ or CIRC may refer to: * Čirč, a village and municipality in northern Slovakia * Circ (duo), an American music duo * Cook Islands Round Cup, top division association football league in the Cook Islands Commercial * China Insurance Regulato ...
= \left begin 1 & 8 & 21 & 2 & 16 & 42 & 3 & 24 & 63 \\ 32 & 100 & 30 & 40 & 125 & 240 & 48 & 150 & 36 \\ 14 & 64 & 27 & 14 & 32 & 18 & 49 & 24 & 81 \end\right


Main properties

:
circ Circ or CIRC may refer to: * Čirč, a village and municipality in northern Slovakia * Circ (duo), an American music duo * Cook Islands Round Cup, top division association football league in the Cook Islands Commercial * China Insurance Regulato ...
=
circ Circ or CIRC may refer to: * Čirč, a village and municipality in northern Slovakia * Circ (duo), an American music duo * Cook Islands Round Cup, top division association football league in the Cook Islands Commercial * China Insurance Regulato ...
; : \bull =
circ Circ or CIRC may refer to: * Čirč, a village and municipality in northern Slovakia * Circ (duo), an American music duo * Cook Islands Round Cup, top division association football league in the Cook Islands Commercial * China Insurance Regulato ...
\left( \otimes \mathbf ^\textsf\right), where \bull denotes the face-splitting product of matrices, :\mathbf \bull = \mathbf
circ Circ or CIRC may refer to: * Čirč, a village and municipality in northern Slovakia * Circ (duo), an American music duo * Cook Islands Round Cup, top division association football league in the Cook Islands Commercial * China Insurance Regulato ...
, where \mathbf is a vector.


Applications

The penetrating face product is used in the
tensor In mathematics, a tensor is an algebraic object that describes a multilinear relationship between sets of algebraic objects associated with a vector space. Tensors may map between different objects such as vectors, scalars, and even other ...
-matrix theory of
digital antenna array Digital antenna array (DAA) is a smart antenna with multi channels digital beamforming, usually by using fast Fourier transform (FFT). The development and practical realization of digital antenna arrays theory started in 1962 under the guidanc ...
s. This operation can also be used in
artificial neural network In machine learning, a neural network (also artificial neural network or neural net, abbreviated ANN or NN) is a computational model inspired by the structure and functions of biological neural networks. A neural network consists of connected ...
models, specifically convolutional layers.


See also

* Frobenius inner product * Pointwise product *
Kronecker product In mathematics, the Kronecker product, sometimes denoted by ⊗, is an operation on two matrices of arbitrary size resulting in a block matrix. It is a specialization of the tensor product (which is denoted by the same symbol) from vector ...
*
Khatri–Rao product In mathematics, the Khatri–Rao product or block Kronecker product of two partitioned matrix, partitioned matrices \mathbf and \mathbf is defined as : \mathbf \ast \mathbf = \left(\mathbf_ \otimes \mathbf_\right)_ in which the ''ij''-th block is ...


References

{{Linear algebra Matrix theory Issai Schur