[Solved] “name ‘self’ is not defined”


You need to first install the package with the command :

pip3 install numpy 

on your shell (I assume you use Python 3).

After you need to write on the top your code :

import numpy

EDIT : With a quick search on Google, I found this :

class neuralNetwork:

    # initialise the neural network:
    def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):
        #set number of nodes in each input, hidden, output layer:
        self.inodes = inputnodes #why can't we immediately use the inputnodes?
        self.hnodes = hiddennodes
        self.onodes = outputnodes

        #Setting the weights:
        self.wih = np.random.normal(0.0, pow(self.hnodes, -0.5),(self.hnodes,self.inodes))
        self.who = np.random.normal(0.0, pow(self.onodes, -0.5),(self.onodes, self.hnodes))    

        #learning rate:
        self.lr = learningrate

        #activation function:
        self.activation_function = lambda x: scipy.special.expit(x) 

        pass

You should check Python tutorials first and be careful with indentation.

1

solved “name ‘self’ is not defined”