HOME

TheInfoList



OR:

In mathematics, 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, an internal binary op ...
that takes two
matrices Matrix most commonly refers to: * ''The Matrix'' (franchise), an American media franchise ** '' The Matrix'', a 1999 science-fiction action film ** "The Matrix", a fictional setting, a virtual reality environment, within ''The Matrix'' (franchi ...
of the same dimensions and produces another matrix of the same dimension as the operands, where each element is the product of elements of the original two matrices. It is to be distinguished from the more common
matrix product In mathematics, particularly 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 ...
. 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 teac ...
or German 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 University of Berlin. He obtained his doctorate in 1901, became lecturer in 1903 and, after a stay at the ...
. The Hadamard product is
associative In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement ...
and distributive. Unlike the matrix product, it is also commutative.


Definition

For two matrices and of the same dimension , the Hadamard product A \circ B (or A \odot B) is a matrix of the same dimension as the operands, with elements given by :(A \circ B)_ = (A \odot B)_ = (A)_ (B)_. For matrices of different dimensions ( and , where or ), the Hadamard product is undefined.


Example

For example, the Hadamard product for a 3 × 4 matrix with a 3 × 4 matrix is : \begin a_ & a_ & a_ & a_\\ a_ & a_ & a_ & a_\\ a_ & a_ & a_ & a_ \end \circ \begin b_ & b_ & b_ & b_\\ b_ & b_ & b_ & b_\\ b_ & b_ & b_ & b_ \end = \begin a_\, b_ & a_\, b_ & a_\, b_ & a_\, b_\\ a_\, b_ & a_\, b_ & a_\, b_ & a_\, b_\\ a_\, b_ & a_\, b_ & a_\, b_ & a_\, b_ \end.


Properties

* The Hadamard product is commutative (when working with a commutative ring),
associative In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement ...
and distributive over addition. That is, if ''A'', ''B'', and ''C'' are matrices of the same size, and ''k'' is a scalar: \begin A \circ B &= B \circ A, \\ A \circ (B \circ C) &= (A \circ B) \circ C, \\ A \circ (B + C) &= A \circ B + A \circ C, \\ \left(kA\right) \circ B &= A \circ \left(kB\right) = k\left(A \circ B\right), \\ A \circ 0 &= 0 \circ 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. Terminology and notation The identity matrix is often denoted by I_n, or simply by I if the size is immaterial or ...
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 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 \circ 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 \boldsymbol is an n \times m matrix obtained by transposing \boldsymbol and applying complex conjugate on each entry (the complex c ...
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) Other uses in arts and entertainment * ''Trace'' ...
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 ...
. A related result for square and , is that the row-sums of their Hadamard product are the diagonal elements of : \sum_i (A \circ B)_ = \left(B^\mathsf A\right)_ = \left(AB^\mathsf\right)_. Similarly, \left(\mathbf\mathbf^*\right) \circ A = _\mathbf A _\mathbf^* Furthermore a Hadamard matrix-vector product can be expressed as: (A \circ B) \mathbf = \operatorname\left( A D_\mathbf B^\mathsf \right) where \operatorname(M) is the vector formed from the diagonals of matrix . *The Hadamard product is a principal
submatrix In mathematics, a matrix (plural matrices) is a rectangular array or table of numbers, symbols, or expressions, arranged in rows and columns, which is used to represent a mathematical object or a property of such an object. For example, \begi ...
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 generalization of the outer product (which is denoted by the same symbol) from vectors to m ...
. * The Hadamard product satisfies the rank inequality \operatorname(A \circ 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 \circ 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 of a linear transformation is a nonzero vector that changes at most by a scalar factor when that linear transformation is applied to it. The corresponding eigenvalue, often denoted ...
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 diagonal m ...
, then \begin D (A \circ B) E &= (D A E) \circ B = (D A) \circ (B E) \\ &= (AE) \circ (D B) = A \circ (D B E). \end * The Hadamard product of two vectors \mathbf a and \mathbf b is the same as matrix multiplication of one vector by 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 diagonal ma ...
of the other vector: \mathbf a \circ \mathbf b = D _ \mathbf b = D _ \mathbf a * The vector to diagonal matrix \operatorname operator may be expressed using the Hadamard product as: \operatorname(\mathbf) = (\mathbf \mathbf^T) \circ 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. Terminology and notation The identity matrix is often denoted by I_n, or simply by I if the size is immaterial or ...
.


The mixed-product property

(A \otimes B) \circ (C \otimes D) = (A \circ C) \otimes (B \circ D) , where \otimes is
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 generalization of the outer product (which is denoted by the same symbol) from vectors to m ...
, assuming A has the same dimensions of C and B with D. (A \bull B) \circ (C \bull D) = (A \circ C) \bull (B \circ D) , where \bull denotes face-splitting product. (A \bull B)(C \ast D) = (A C) \circ (B D), where \ast is column-wise
Khatri–Rao product In mathematics, the Khatri–Rao product of matrices defined as : \mathbf \ast \mathbf = \left(\mathbf_ \otimes \mathbf_\right)_ in which the ''ij''-th block is the sized Kronecker product of the corresponding blocks of A and B, assuming the numb ...
.


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 University of Berlin. He obtained his doctorate in 1901, became lecturer in 1903 and, after a stay at the ...
. For two positive-semidefinite matrices and , it is also known that the
determinant In mathematics, the determinant is a scalar value that is a function of the entries of a square matrix. It characterizes some properties of the matrix and the linear map represented by the matrix. In particular, the determinant is nonzero if an ...
of their Hadamard product is greater than or equal to the product of their respective determinants: \det( \circ ) \ge \det() \det().


In programming languages

Hadamard multiplication is built into certain
programming languages A programming language is a system of notation for writing computer program, computer programs. Most programming languages are text-based formal languages, but they may also be visual programming language, graphical. They are a kind of computer ...
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, implementatio ...
,
GNU Octave GNU Octave is a high-level programming language primarily intended for scientific computing and numerical computation. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a langu ...
,
GAUSS Johann Carl Friedrich Gauss (; german: Gauß ; la, Carolus Fridericus Gauss; 30 April 177723 February 1855) was a German mathematician and physicist who made significant contributions to many fields in mathematics and science. Sometimes refer ...
and
HP Prime The HP Prime Graphing Calculator is a graphing calculator introduced by Hewlett-Packard in 2013 and currently manufactured by HP Inc. It was designed with features resembling those of smartphones, such as a full-color touchscreen display and ...
, it is known as ''array multiplication'', or in
Julia Julia is usually a feminine given name. It is a Latinate feminine form of the name Julio and Julius. (For further details on etymology, see the Wiktionary entry "Julius".) The given name ''Julia'' had been in use throughout Late Antiquity (e. ...
''broadcast multiplication'', with the symbol .*. In Fortran, R, APL, J and
Wolfram Language The Wolfram Language ( ) is a general multi-paradigm programming language developed by Wolfram Research. It emphasizes symbolic computation, functional programming, and rule-based programming and can employ arbitrary structures and data. It i ...
(
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
), it is done through simple multiplication operator *, whereas the matrix product is done through the function matmul, %*%, +.×, +/ .* and the . operators, respectively. In
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pr ...
with the NumPy numerical library, multiplication of objects as a*b produces the Hadamard product, and multiplication as a@b produces the matrix product. With the SymPy symbolic library, multiplication of objects as both a*b and a@b will produce the matrix product, the Hadamard product can be obtained with a.multiply_elementwise(b). In C++, the
Eigen Eigen may refer to: * Eigen (C++ library), computer programming library for matrix and linear algebra operations * Eigen Technologies, the Document AI software company * Eigen, Schwyz, settlement in the municipality of Alpthal in the canton of S ...
library provides a cwiseProduct member function for the class (a.cwiseProduct(b)), while the
Armadillo Armadillos (meaning "little armored ones" in Spanish) are New World placental mammals in the order Cingulata. The Chlamyphoridae and Dasypodidae are the only surviving families in the order, which is part of the superorder Xenarthra, along wi ...
library uses the operator % to make compact expressions (a % b; a * b is a matrix product). R packag
matrixcalc
introduces 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 ( ) is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image ...
. The decoding step involves an entry-for-entry product, in other words the Hadamard product. In
image processing An image is a visual representation of something. It can be two-dimensional, three-dimensional, or somehow otherwise feed into the visual system to convey information. An image can be an artifact, such as a photograph or other two-dimension ...
, 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 inquiry devoted to understanding and building methods that 'learn', that is, methods that leverage data to improve performance on some set of tasks. It is seen as a part of artificial intelligence. Machin ...
literature, for example to describe the architecture of recurrent neural networks as GRUs or LSTMs. It is also used to study statistical properties of random vectors and matrices.


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


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 = \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 = \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; : \bull = circ\left( \otimes \mathbf ^\textsf\right), where \bull denotes the face-splitting product of matrices, :\mathbf \bull = \mathbf circ, 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 related to a vector space. Tensors may map between different objects such as vectors, scalars, and even other tenso ...
-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 Artificial neural networks (ANNs), usually simply called neural networks (NNs) or neural nets, are computing systems inspired by the biological neural networks that constitute animal brains. An ANN is based on a collection of connected units ...
models, specifically convolutional layers.


See also

*
Frobenius inner product In mathematics, the Frobenius inner product is a binary operation that takes two matrices and returns a scalar. It is often denoted \langle \mathbf,\mathbf \rangle_\mathrm. The operation is a component-wise inner product of two matrices as though t ...
*
Pointwise product In mathematics, the pointwise product of two functions is another function, obtained by multiplying the images of the two functions at each value in the domain. If and are both functions with domain and codomain , and elements of can be mu ...
*
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 generalization of the outer product (which is denoted by the same symbol) from vectors to m ...
*
Khatri–Rao product In mathematics, the Khatri–Rao product of matrices defined as : \mathbf \ast \mathbf = \left(\mathbf_ \otimes \mathbf_\right)_ in which the ''ij''-th block is the sized Kronecker product of the corresponding blocks of A and B, assuming the numb ...


References

{{Linear algebra Matrix theory