title: sigmoid in python that can take scalar, vector or matrix
body: <p>The following code is written in Octave Programming language</p>
  
  <pre><code>g =1./(1+e.^-(z)
  </code></pre>
  
  <p>It computes a sigmoid function and can take scalar, vector or Matrix. For example 
  if I put the above into a function sigmoid(z), where z=0, the result will be:</p>
  
  <pre><code>result=sigmoid(0)
  </code></pre>
  
  <p>The result will be scalar ( 0.5)
  if the pass a vector say z= [ 0.2, 0.4, 0.1], it would output a vector for result as:-</p>
  
  <pre><code> result=sigmoid(z)
  </code></pre>
  
  <p>result is a vector:</p>
  
  <pre><code> 0.54983   0.59869   0.52498
  </code></pre>
  
  <p>if z is a matrix like</p>
  
  <pre><code> z=[ 0.2 0.4; 0.5 0.7; 0.9 .004]
  
  result = sigmoid(z)
  </code></pre>
  
  <p>the result is = </p>
  
  <pre><code>  0.54983   0.59869
    0.62246   0.66819
    0.71095   0.50100
  </code></pre>
  
  <p>Now how do I implement a similar method in Python?. I tried the below code, </p>
  
  <pre><code>g=1./ (1 + math.exp(-z))
  </code></pre>
  
  <p>But it works only for scalar. Not for vector and Matrix. what am I doing wrong.
  sorry my question before was not very clear. I am re-edited it.  </p>