我正在从Coursera学习机器学习。我正在尝试计算sigmoid函数,我有以下代码:
function g = sigmoid(z)
%SIGMOID Compute sigmoid functoon
% J = SIGMOID(z) computes the sigmoid of z.
% You need to return the following variables correctly
g = zeros(size(z));
% ====================== YOUR CODE HERE ======================
% Instructions: Compute the sigmoid of each value of z (z can be a matrix,
% vector or scalar).
g = (1 + exp(-1 * z)) .^ -1;
g = 1/(1+ (1/exp(z)))
% my question is why the first g calculation works for matrix(say …Run Code Online (Sandbox Code Playgroud)