text: import numpy as np  
  # http://iamtrask.github.io/2015/07/27/python-network-part2/
  # compute sigmoid nonlinearity
  def sigmoid(x):
      output = 1/(1+np.exp(-x))
      return output
  
  # convert output of sigmoid function to its derivative
  def sigmoid_output_to_derivative(output):
      return output*(1-output)
      
  # input dataset
  X = np.array([  [0,1],
                  [0,1],
                  [1,0],
                  [1,0] ])
      
  # output dataset            
  y = np.array([[0,0,1,1]]).T
  
  # seed random numbers to make calculation
  # deterministic (just a good practice)
  np.random.seed(1)
  
  
  count = 1000 * 10
  inputs = np.random.random((count,3)) 
  labels = []
  for i in xrange(count):
      inputs[ i ].sort();
      v = inputs[ i ];
      d = np.sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] )
      labels.append( d )
  X = inputs
  y = np.array([labels]).T
   
  # initialize weights randomly with mean 0
  synapse_0 = 2*np.random.random((3,1)) - 1
  
  for iter in xrange(1000 * 100): # even just 100 is pretty good...
  
      # forward propagation
      layer_0 = X
      layer_1 = sigmoid(np.dot(layer_0,synapse_0))
  
      # how much did we miss?
      layer_1_error = layer_1 - y
  
      # multiply how much we missed by the 
      # slope of the sigmoid at the values in l1
      layer_1_delta = layer_1_error * sigmoid_output_to_derivative(layer_1)
      synapse_0_derivative = np.dot(layer_0.T,layer_1_delta)
  
      # update weights
      synapse_0 -= synapse_0_derivative
  
  print "Output After Training:"
  print layer_1
   
  print "Error After Training:"
  print np.mean(np.abs(layer_1-y))
  print synapse_0.T, 'is go'
  
  
  