神剑山庄资源网 Design By www.hcban.com

两个三维矩阵的乘法怎样计算呢"htmlcode">

import tensorflow as tf
import numpy as np
a = tf.constant(np.arange(1, 13, dtype=np.float32), shape=[2, 2, 3])
b = tf.constant(np.arange(1, 13, dtype=np.float32), shape=[2, 3, 2])
c = tf.matmul(a, b)
# c = tf.matmul(a, b)
sess = tf.Session()
print("a*b = ", sess.run(c))
c1 = tf.matmul(a[0, :, :], b[0, :, :])
print("a[1]*b[1] = ", sess.run(c1))

运行结果:

tensorflow多维张量计算实例

计算结果表明,两个三维矩阵相乘,对应位置的最后两个维度的矩阵乘法。

再验证高维的张量乘法:

import tensorflow as tf
import numpy as np
a = tf.constant(np.arange(1, 36, dtype=np.float32), shape=[3, 2, 2, 3])
b = tf.constant(np.arange(1, 36, dtype=np.float32), shape=[3, 2, 3, 2])
c = tf.matmul(a, b)
# c = tf.matmul(a, b)
sess = tf.Session()
print("a*b = ", sess.run(c))
c1 = tf.matmul(a[0, 0, :, :], b[0, 0, :, :])
print("a[1]*b[1] = ", sess.run(c1))

运行结果:

tensorflow多维张量计算实例

以上这篇tensorflow多维张量计算实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
tensorflow,多维,张量,计算

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“tensorflow多维张量计算实例”

暂无tensorflow多维张量计算实例的评论...