- 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]]
推薦閱讀
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- 數據庫應用實戰
- DB29forLinux,UNIX,Windows數據庫管理認證指南
- 從0到1:數據分析師養成寶典
- Voice Application Development for Android
- 新型數據庫系統:原理、架構與實踐
- Python數據分析、挖掘與可視化從入門到精通
- MySQL從入門到精通(第3版)
- 醫療大數據挖掘與可視化
- 數據庫應用基礎教程(Visual FoxPro 9.0)
- 大數據營銷:如何讓營銷更具吸引力
- Hadoop 3.x大數據開發實戰
- Python金融實戰
- AI時代的數據價值創造:從數據底座到大模型應用落地
- 跨領域信息交換方法與技術(第二版)