Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Python vs Jupyter
#1
Hi to everyone,

In a first step I want to admit that I´m a very very beginner so please dont judge me on this question - I sure it is very simple but I don´t get it by myself.

I was reading the book Make Your Own Neural Network from Rashid, Tariq and he is using Ipython with jupyter notebook when he was explaining the code.
So I decided to use also Jupyter Notebook and the following code worked out there - I had an output generated - when I pasted the same code to my python visual basic code to run it there it just throwed nothing out. (no Error no exception nothing ..)

just follwing output from termin:

PS C:\Users\Admin\Desktop\NN> c:; cd 'c:\Users\Admin\Desktop\NN'; & 'C:\Users\Admin\AppData\Local\Programs\Python\Python39\python.exe' 'c:\Users\Admin\.vscode\extensions\ms-python.python-2021.10.1336267007\pythonFiles\lib\python\debugpy\launcher' '62379' '--' 'c:\Users\Admin\Desktop\NN\#Neuronales Netzwerk.py'

And I can´t find the problem :( can someone help and explain it to me that I can also understand it.

Code as follows:

#Neuronales Netzwerk import numpy # scipy.special for the sigmoid function expit() import scipy.special # neural network class definition 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 self.hnodes = hiddennodes self.onodes = outputnodes # link weight matrices, wih and who # weights inside the arrays are w_i_j, where link is from node i to node j in the next layer # w11 w21 # # w12 w22 etc self.wih = numpy.random.normal(0.0, pow(self.inodes, -0.5), (self.hnodes, self.inodes)) self.who = numpy.random.normal(0.0, pow(self.hnodes, -0.5), (self.onodes, self.hnodes)) # learning rate self.lr = learningrate # activation function is the sigmoid function self.activation_function = lambda x: scipy.special.expit(x) pass # train the neural network def train(self, inputs_list, targets_list): # convert inputs list to 2d array inputs = numpy.array(inputs_list, ndmin=2).T targets = numpy.array(targets_list, ndmin=2).T # calculate signals into hidden layer hidden_inputs = numpy.dot(self.wih, inputs) # calculate the signals emerging from hidden layer hidden_outputs = self.activation_function(hidden_inputs) # calculate signals into final output layer final_inputs = numpy.dot(self.who, hidden_outputs) # calculate the signals emerging from final output layer final_outputs = self.activation_function(final_inputs) # output layer error is the (target - actual) output_errors = targets - final_outputs # hidden layer error is the output_errors, split by weights, recombined at hidden nodes hidden_errors = numpy.dot(self.who.T, output_errors) # update the weights for the links between the hidden and output layers self.who += self.lr * numpy.dot((output_errors * final_outputs * (1.0 - final_outputs)), numpy.transpose(hidden_outputs)) # update the weights for the links between the input and hidden layers self.wih += self.lr * numpy.dot((hidden_errors * hidden_outputs * (1.0 - hidden_outputs)), numpy.transpose(inputs)) pass # query the neural network def query(self, inputs_list): # convert inputs list to 2d array inputs = numpy.array(inputs_list, ndmin=2).T # calculate signals into hidden layer hidden_inputs = numpy.dot(self.wih, inputs) # calculate the signals emerging from hidden layer hidden_outputs = self.activation_function(hidden_inputs) # calculate signals into final output layer final_inputs = numpy.dot(self.who, hidden_outputs) # calculate the signals emerging from final output layer final_outputs = self.activation_function(final_inputs) return final_outputs # number of input, hidden and output nodes input_nodes = 3 hidden_nodes = 3 output_nodes = 3 # learning rate is 0.3 learning_rate = 0.3 # create instance of neural network n = neuralNetwork(input_nodes,hidden_nodes,output_nodes,learning_rate) n.query([1.0,0.5,1.5])
Input is the n.query ([1.0,0.5,1.5])
The ouput should be an array with the weighted values.
Reply
#2
In Jupyter the results of a cell are automatically output.
To see the output in VS code you would use print
print(n.query([1.0,0.5,1.5]))
Reply
#3
Thank you very much for your help. :)
I also tried it with print but not like you did - learned something.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 1 5,377 Jun-04-2024, 10:55 PM
Last Post: Drone4four
  Install python 2.7 in jupyter lab raman 28 8,532 Jun-01-2024, 01:53 PM
Last Post: snippsat
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 2,435 Jan-21-2023, 05:01 PM
Last Post: nicholas
  Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2 Newtopython123 10 37,547 Apr-25-2019, 07:30 AM
Last Post: banu0395
  Jupyter and python terminal dervast 3 4,381 Mar-29-2019, 02:08 PM
Last Post: dervast
  Code runs as pure python but not jupyter notebook miner_tom 3 5,364 Aug-22-2018, 04:00 PM
Last Post: miner_tom
  1 What is Jupyter? and what's the difference between it and "pure python"? InigoSJ 2 4,306 Apr-05-2018, 07:24 PM
Last Post: InigoSJ

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.