【Pytorch学习笔记】从零开始搭建神经网络(1/3)

先列代码,从这段代码里,能了解很多python和pytorch需要懂的逻辑和代码知识

明天组会,今天看了一段先放着

import numpy as np

def sigmoid(x):
  # Our activation function: f(x) = 1 / (1 + e^(-x))
  return 1 / (1 + np.exp(-x))

class Neuron:
  def __init__(self, weights, bias):
    self.weights = weights
    self.bias = bias

  def feedforward(self, inputs):
    # Weight inputs, add bias, then use the activation function
    total = np.dot(self.weights, inputs) + self.bias
    return sigmoid(total)

weights = np.array([0, 1]) # w1 = 0, w2 = 1
bias = 4                   # b = 4
n = Neuron(weights, bias)

x = np.array([2, 3])       # x1 = 2, x2 = 3
print(n.feedforward(x))    # 0.9990889488055994

结果图:
【Pytorch学习笔记】从零开始搭建神经网络(1/3)_第1张图片

下一节:类之间的调用

你可能感兴趣的:(Python/Pycharm,深度学习/PyTorch,pytorch,神经网络,深度学习)