例子:

A = \begin{bmatrix} 1 & 2 \ 3 & 4 \end{bmatrix},B = \begin{bmatrix} 5 & 6 \ 7 & 8 \end{bmatrix}

则 A 和 B 的哈达玛积为

A \circ B = \begin{bmatrix} 1 \times 5 & 2 \times 6 \ 3 \times 7 & 4 \times 8 \end{bmatrix} = \begin{bmatrix} 5 & 12 \ 21 & 32 \end{bmatrix}。

在Python中,可以使用numpy库中的multiply()函数实现矩阵的哈达玛积。示例代码如下:

import numpy as np

A = np.array([[1, 2], [3, 4]]) B = np.array([[5, 6], [7, 8]])

C = np.multiply(A, B)

print(C)

输出结果为:

[[ 5 12] [21 32]]

哈达玛积(Hadamard product)是矩阵的一类运算,若A=(aij)和B=(bij)是两个同阶矩阵,若cij=aij×bij,则称矩阵C=(cij)为A和B的哈达玛积,或称基本积

原文地址: https://www.cveoy.top/t/topic/vKD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录