-
-
Save miloharper/62fe5dcc581131c96276 to your computer and use it in GitHub Desktop.
from numpy import exp, array, random, dot | |
training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]]) | |
training_set_outputs = array([[0, 1, 1, 0]]).T | |
random.seed(1) | |
synaptic_weights = 2 * random.random((3, 1)) - 1 | |
for iteration in xrange(10000): | |
output = 1 / (1 + exp(-(dot(training_set_inputs, synaptic_weights)))) | |
synaptic_weights += dot(training_set_inputs.T, (training_set_outputs - output) * output * (1 - output)) | |
print 1 / (1 + exp(-(dot(array([1, 0, 0]), synaptic_weights)))) |
python 3 version:
remember python -m pip install numpy
from numpy import exp, array, random, dot
training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]])
training_set_outputs = array([[0, 1, 1, 0]]).T
random.seed(1)
synaptic_weights = (2 * random.random((3, 1)) - 1)
for iteration in range(10000):
output = (1 / (1 + exp(-(dot(training_set_inputs, synaptic_weights)))))
synaptic_weights += dot(training_set_inputs.T, (training_set_outputs - output) * output * (1 - output))
print (1 / (1 + exp(-(dot(array([1, 0, 0]), synaptic_weights)))))
I am novice in python. Installed numpy via command line, updated to newest version to work with Python v3.
Copied/pasted proposed updated code with parentheses (starting from: from numpy import exp, array, random, dot... ending with: print (1 / (1 + exp(-(dot(array([1, 0, 0]), synaptic_weights))))).
Executed the code in Pycharm.
It shows me the Error:
xxxxxxxxxxxxxxxs/App.py", line 7
output = (1 / (1 + exp(-(dot(training_set_inputs, synaptic_weights)))))
^
IndentationError: expected an indented block
which indent is meant here? please advice..
thank you((-::
if we using if or for in python
we need to write it like this
for xx in xx:
....output = xx
put 4 (blank space?) in front of the ( )output
sorry for my grammar _(:3
python 3 version:
remember python -m pip install numpy
from numpy import exp, array, random, dot
training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]])
training_set_outputs = array([[0, 1, 1, 0]]).T
random.seed(1)
synaptic_weights = (2 * random.random((3, 1)) - 1)
for iteration in range(10000):
output = (1 / (1 + exp(-(dot(training_set_inputs, synaptic_weights)))))
synaptic_weights += dot(training_set_inputs.T, (training_set_outputs - output) * output * (1 - output))
print (1 / (1 + exp(-(dot(array([1, 0, 0]), synaptic_weights)))))