我正在从 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 100*2) however the second only works for (100*1) as both are trying to do the same this.
% =============================================================
end