tensorflow-矩阵乘法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tensorflow-矩阵乘法相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 12 18:18:06 2018

@author: myhaspl
"""

import tensorflow as tf 
w1=tf.Variable(tf.random_normal([2,5],mean=1.0,stddev=1.0))
w2=tf.Variable(tf.random_normal([5,1],mean=1.0,stddev=1.0))
x=tf.constant([[0.9,2.8]])
y1=tf.matmul(x,w1)
y2=tf.matmul(y1,w2)

with  tf.Session() as ess:
    tf.global_variables_initializer().run()

    print(y2.eval())

[[16.396265]]

以上是关于tensorflow-矩阵乘法的主要内容,如果未能解决你的问题,请参考以下文章