#!/usr/bin/python
import numpy as np

'''define'''
class Network:
    def __init__(self,sizes):
        self.num_layers=len(sizes)
        self.sizes=sizes
        self.biases=[np.random.randn(y,1) for y in sizes[1:]]  # 3*1 and 1*1
        self.weights=[np.random.randn(x,y) \
                    for x,y in zip(sizes[1:],sizes[:-1])]      # 3*2 and 1*3

    def feedforward(self,a):
        for b,w in zip(self.biases,self.weights):
            a=sigmoid(np.dot(w,a)+b)
        return a

def sigmoid(z):
    return 1.0/(1.0+np.exp(-z))

'''invoke'''
net=Network([2,3,1])
net.feedforward([[2],[3]])
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐