我试图在Tensorflow中创建一个近似正弦函数的神经网络.我已经找到了一些通用函数逼近器的例子,但是我并没有完全理解代码,因为我对Tensorflow很新,我想自己编写代码来理解每一步.
这是我的代码:
import tensorflow as tf
import numpy as np
import math, random
import matplotlib.pyplot as plt
# Create the arrays x and y that contains the inputs and the outputs of the function to approximate
x = np.arange(0, 2*np.pi, 2*np.pi/1000).reshape((1000,1))
y = np.sin(x)
# plt.plot(x,y)
# plt.show()
# Define the number of nodes
n_nodes_hl1 = 100
n_nodes_hl2 = 100
# Define the number of outputs and the learn rate
n_classes = 1
learn_rate = 0.1
# Define input / …Run Code Online (Sandbox Code Playgroud) python mathematical-optimization approximation neural-network tensorflow