MathPHP\LinearAlgebra\Matrix::hadamardProduct PHP Method

hadamardProduct() public method

A binary operation that takes two matrices of the same dimensions, and produces another matrix where each element ij is the product of elements ij of the original two matrices. https://en.wikipedia.org/wiki/Hadamard_product_(matrices) (A∘B)ᵢⱼ = (A)ᵢⱼ(B)ᵢⱼ
public hadamardProduct ( Matrix $B ) : Matrix
$B Matrix
return Matrix
    public function hadamardProduct(Matrix $B) : Matrix
    {
        if ($B->getM() !== $this->m || $B->getN() !== $this->n) {
            throw new Exception\MatrixException('Matrices are not the same dimensions');
        }
        $m = $this->m;
        $n = $this->n;
        $A = $this->A;
        $B = $B->getMatrix();
        $A∘B = [];
        for ($i = 0; $i < $m; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $A∘B[$i][$j] = $A[$i][$j] * $B[$i][$j];
            }
        }
        return MatrixFactory::create($A∘B);
    }