官术网_书友最值得收藏!

Matrix multiplication

Matrix multiplication of matrices A and B is a third matrix, C:

C = AB

The element-wise product of matrices is called a Hadamard product and is denoted as A.B.

The dot product of two vectors x and y of the same dimensionality is the matrix product x transposing y. Matrix product C = AB is like computing Ci,j as the dot product between row i of matrix A and column j of matrix B:

The following example shows the Hadamard product and dot product using tensor objects:

import tensorflow as tf

mat1 = tf.constant([[4, 5, 6],[3,2,1]])
mat2 = tf.constant([[7, 8, 9],[10, 11, 12]])

# hadamard product (element wise)
mult = tf.multiply(mat1, mat2)

# dot product (no. of rows = no. of columns)
dotprod = tf.matmul(mat1, tf.transpose(mat2))

with tf.Session() as sess:
print(sess.run(mult))
print(sess.run(dotprod))

The output of the listing is shown as follows:

[[28 40 54][30 22 12]]
[[122 167][ 46 64]]
主站蜘蛛池模板: 三门县| 江川县| 遂溪县| 兴义市| 宜丰县| 齐齐哈尔市| 义乌市| 定西市| 海伦市| 越西县| 环江| 长沙市| 清徐县| 宜黄县| 高陵县| 保定市| 清新县| 绥化市| 田阳县| 康保县| 建始县| 洛扎县| 柳河县| 同德县| 邯郸市| 潞城市| 南乐县| 东辽县| 类乌齐县| 略阳县| 涪陵区| 珠海市| 壤塘县| 南川市| 内黄县| 霸州市| 五家渠市| 秦安县| 英吉沙县| 岐山县| 赤峰市|