TensorFlow 矩阵变量初始化后的计算例子

import tensorflow as tf
import numpy as np

x = tf.placeholder(tf.float32, shape=(1024, 1024))  #placeholder是占位符,申明x是1024*1024维度的矩阵,此时并没有初始化具体值。要在Session中初始化后,才能run出y

y = tf.matmul(x, x)  #两个矩阵相乘

with tf.Session() as sess:
# print(sess.run(y)) # ERROR:此处x还没有赋值
rand_array = np.random.rand(1024, 1024)  #rand_array 定义一个1024*1024维度的随机值,在下一步赋给x
print(sess.run(y, feed_dict={x: rand_array}))  #feed_dict为赋值的用法
原文地址:https://www.cnblogs.com/junblog/p/10621790.html