📅  最后修改于: 2023-12-03 15:29:31.856000             🧑  作者: Mango
当您尝试在TensorFlow中使用random_normal函数时,可能会遇到AttributeError。这个错误通常是因为您的TensorFlow版本过旧而未包含random_normal函数。
要解决此问题,您需要升级TensorFlow版本。可以使用以下命令在终端或Anaconda Prompt中升级TensorFlow版本:
!pip install --upgrade tensorflow
这将在您的计算机上更新TensorFlow版本并安装random_normal函数。
注意:在升级TensorFlow之前,请确保您的计算机已安装pip。
import tensorflow as tf
input_data = tf.placeholder(dtype=tf.float32, shape=[None, 10])
w = tf.Variable(tf.random_normal(shape=[10, 5]))
output = tf.matmul(input_data, w)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
output_data = sess.run(output, feed_dict={input_data: [[1]*10]*3})
print(output_data)
如果您的TensorFlow版本过旧,您将看到以下错误:
AttributeError: module 'tensorflow' has no attribute 'random_normal'
在这种情况下,请使用上面提供的命令更新TensorFlow版本。