Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x tf.mul和tf.sqrt中的不确定参数_Python 3.x_Tensorflow - Fatal编程技术网

Python 3.x tf.mul和tf.sqrt中的不确定参数

Python 3.x tf.mul和tf.sqrt中的不确定参数,python-3.x,tensorflow,Python 3.x,Tensorflow,我正试图借助一些git示例和教程了解Tensorflow的基础知识,但我被困在无法绘制高斯分布图的地方,这就是我所做的 x = tf.lin_space(-3.0, 3.0, 32) sess = tf.InteractiveSession() s = 0 mean = 0 gauss = (tf.exp(tf.negative(tf.pow(x - mean, 2) / (2 * tf.pow(s, 2)))) * (1.0 / (s * tf.sqrt(2 * 3.1415)))) pl

我正试图借助一些git示例和教程了解Tensorflow的基础知识,但我被困在无法绘制高斯分布图的地方,这就是我所做的

x = tf.lin_space(-3.0, 3.0, 32)

sess = tf.InteractiveSession()

s = 0
mean = 0
gauss = (tf.exp(tf.negative(tf.pow(x - mean, 2) / (2 * tf.pow(s, 2)))) * (1.0 / (s * tf.sqrt(2 * 3.1415))))
plt.plot(x.eval(), gauss.eval())
plt.show()
最初我得到了TypeError,因为在tf.pow中有浮点参数,即2.0,而不是2。我甚至尝试过将类型更改,但tf.to_float,但这也没有帮助,我同意了

ValueError: Tensor conversion requested dtype float32 for Tensor with dtype int32: 'Tensor("mul:0", shape=(), dtype=int32)'

只是猜测一下,不应该有tf.matmul而不是2*tf.pows,2?

解决了这个问题。pow的输入应为浮点数。因此,s应该是一个浮动

x = tf.lin_space(-3.0, 3.0, 32)

sess = tf.InteractiveSession()

s = 1.0 # need to be a float
mean = 0
gauss = (tf.exp(tf.negative(tf.pow(x - mean, 2) / (2 * tf.pow(s, 2)))) * (1.0 / (s * tf.sqrt(2 * 3.1415))))
plt.plot(x.eval(), gauss.eval())
plt.show()

希望这有帮助。

谢谢,但图表没有显示任何内容,有什么帮助吗?我想s应该等于1,因为您正在计算与高斯分布相关的值。在您的代码中,s=0.0,因为高斯变量给出“nan”。这就是不显示图表的原因