title: sigmoid function - TypeError
body: <p>Apologies if I don't get this right the first time, as I am new to both this forum and Python. I am attempting to do logistic regression and would like to calculate the sigmoid function. </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import numpy as np
  
  csv_file_object = csv.reader(open('train.csv', 'rb')) 
  header = csv_file_object.next()                       
  
  train_data=[]                                           
  
  for row in csv_file_object:                             
      train_data.append(row[1:])                          
  
  train_data = np.array(train_data) 
  
  X = train_data
  
  X = np.c_[ np.ones(N), X ]   # print type(X) gives &lt;type 'numpy.ndarray'&gt;
  
  def sigmoid(z):
      s = 1.0 / (1.0 + np.exp**(-1.0 * z))
      return s
  
  print sigmoid(X)
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <p>When I run this I get the following error:</p>
  
  <p>Traceback (most recent call last):
    File "C:\Users...", line 63, in </p>
  
  <pre><code>print sigmoid(X)
  </code></pre>
  
  <p>File "C:\Users...", line 59, in sigmoid</p>
  
  <pre><code>s = 1.0 / (1.0 + np.exp**(-1.0 * z))
  </code></pre>
  
  <p>TypeError: unsupported operand type(s) for *: 'float' and 'numpy.ndarray'</p>
  
  <p>I have tried switching the 1.0's to 1's and then get 'int' instead of 'float' in the error and using '.astype(np.float)' and other attempts. I have looked for similar questions and have looked at the documentation but have been unable to find a solution (or understand that I was indeed reading a solution!):
  <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.exp.html" rel="nofollow noreferrer">http://docs.scipy.org/doc/numpy/reference/generated/numpy.exp.html</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3985619/how-to-calculate-a-logistic-sigmoid-function-in-python">How to calculate a logistic sigmoid function in Python?</a></p>
  
  <p>My understanding is the exponential function should perform an element-wise exponentiation for each element in the array. </p>
  
  <p>What am I missing?</p>