【发布时间】:2020-09-27 04:46:33
【问题描述】:
我正在尝试创建一个神经网络,但是当我尝试实现 sigmoid 函数(在这种情况下导入或手动创建它)时,它只是说变量 sigmoid 不存在
这是我的代码
另外,我在 Anaconda 中使用 Visual Studio 代码
from matplotlib import pylab
import pylab as plt
import numpy as np
class NeuralNetwork:
def __init__(self,x,y):
self.input = x
self.weights1 = np.random.rand(self.input.shape[1],4)
self.weights2 = np.random.rand(4,1)
self.y = y
self.output = np.zeros(self.y.shape)
def sigmoid(self,x):
return (1/(1+np.exp(-x)))
def feedforward(self):
self.layer1 = sigmoid(np.dot(self.input, self.weights1))
self.output = sigmoid(np.dot(self.layer1, self.weights2))```
【问题讨论】:
-
你必须使用 self.sigmoid() 因为 sigmoid 是类的方法
-
如果我在下面的回答对您有所帮助,请考虑支持并接受它。它会帮助我、你和其他试图回答类似问题的人。
标签: python neural-network sigmoid