本文实例为大家分享了python绘制高斯曲线的具体代码,供大家参考,具体内容如下
源码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import numpy as np import matplotlib.pyplot as plt import math import mpl_toolkits.mplot3d import tensorflow.compat.v1 as tf tf.disable_v2_behavior() #import tensorflow as tf from sklearn import datasets sess = tf.InteractiveSession() gamma = tf.constant( - 1.0 ) x, y = np.mgrid[ - 2 : 2 : 0.01 , - 2 : 2 : 0.01 ] x_data = tf.placeholder(shape = [ 400 , 400 ], dtype = tf.float32) y_data = tf.placeholder(shape = [ 400 , 400 ], dtype = tf.float32) Kernel = tf.exp(tf.multiply(gamma, tf.add((x_data * x_data),(y_data * y_data)))) Kernel = sess.run(Kernel, feed_dict = {x_data: x,y_data: y}) ax = plt.subplot( 111 , projection = '3d' ) ax.plot_surface(x, y, Kernel, rstride = 1 , cstride = 1 , cmap = 'rainbow' , alpha = 0.9 ) #绘面 ax.set_xlabel( 'x' ) ax.set_ylabel( 'y' ) ax.set_zlabel( 'Kernel' ) plt.show() |
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/m0_46278037/article/details/113833114