- Neural Network Programming with TensorFlow
- Manpreet Singh Ghotra Rajdeep Dua
- 153字
- 2021-07-02 15:17:07
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]]
推薦閱讀
- 信息系統(tǒng)與數(shù)據(jù)科學(xué)
- Python醫(yī)學(xué)數(shù)據(jù)分析入門
- 數(shù)據(jù)庫程序員面試筆試真題庫
- Spark大數(shù)據(jù)編程實用教程
- 新基建:數(shù)據(jù)中心創(chuàng)新之路
- 達夢數(shù)據(jù)庫運維實戰(zhàn)
- 視覺大數(shù)據(jù)智能分析算法實戰(zhàn)
- Mastering LOB Development for Silverlight 5:A Case Study in Action
- 計算機視覺
- The Natural Language Processing Workshop
- Spring MVC Beginner’s Guide
- 離線和實時大數(shù)據(jù)開發(fā)實戰(zhàn)
- 大數(shù)據(jù)計算系統(tǒng)原理、技術(shù)與應(yīng)用
- 精通Neo4j
- 數(shù)據(jù)庫技術(shù)與應(yīng)用:SQL Server 2008