function g = sigmoid(z)

%SIGMOID Compute sigmoid function
%J = SIGMOID(z) computes the sigmoid of z.

g = 1.0 ./ (1.0 + exp(-z));


I'm going through the Andrew Ng Coursera course. I doubt that how exp(-z) is computed directly while z is a matrix?

  • $\begingroup$ Word of advice: You are really have to think in terms of vectors and matrices instead of scalars (ok, an scalar is just a funny word to say "single number"). This will be particularly important when calculating the loss too! $\endgroup$ Jan 14, 2019 at 21:35

1 Answer 1


In many languages and libraries, operations that apply to a scalar can be applied to vectors, matrices and tensors. They're just applied element-wise, and the result is another vector, matrix, etc with each value transformed by that function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.