I am trying to get a dimension of 103 by 55 of the output c4 below by using a loop in python . However, I could not make the loop work as the output c4 is giving me one single value
my code in pyhton :
for j in range(np.int64(n)):
for i in range(np.int64(m)):
c4 = np.sum(np.log(f))
where n=55 and m=103 and f is a matrix of dimension 1 by 441 . My question is how can I rewrite the line c4 = np.sum(np.log(f)) to incorporate i and j and get a dimension of 103 by 55 in c4 .
This is the working matlab version of the code :
for j=1:n
for i=1:m
c4(i,j) = sum(log(f));
end
end
c4 = np.sum(np.log(f)). Do you want to apply the log and sum for each row inf?c4[:n,:m] = np.sum(np.log(f))(withc4created before the loop). Note that Python do not have a JIT as opposed to Matlab so a direct translation is clearly not a good idea (like for any code translation from one language to another, including even natural languages). You should learn to use vectorization in Numpy (note that this is already important in Matlab for sake of performance). Ifc4is a scalar, then usec4 = np.sum(np.log(f))without loops.