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

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]]
主站蜘蛛池模板: 丰台区| 米林县| 济宁市| 香格里拉县| 偏关县| 广南县| 德阳市| 上饶市| 山东省| 阜平县| 太白县| 潮安县| 莲花县| 乌海市| 奎屯市| 永川市| 扎赉特旗| 瑞丽市| 扎鲁特旗| 治多县| 吴忠市| 泗阳县| 简阳市| 广安市| 惠水县| 涞水县| 库伦旗| 浙江省| 南昌县| 泸州市| 隆子县| 松桃| 冕宁县| 三亚市| 遵义市| 石楼县| 鲜城| 乳山市| 获嘉县| 夏邑县| 宁化县|