title: Conversion of Matlab loop to Python loop
body: <p>I am trying to convert the following Matlab code to Python :</p>
  <pre class="lang-matlab prettyprint-override"><code>for j=1:n
      for i=1:m
          a1(i,j) = sum(-4*f*d(i))*log(NormPS{i,j}(f1:f2)));
      end
  end
  </code></pre>
  <p>where n=55 and m=103; f has a 1 by 441 dimension matrix (consider any random values)
  f1=10 and f2=450 and <code>log(NormPS{i,j}(f1:f2)))</code> gives a matrix of 441 by 1 dimension and <code>d</code> is a 1 by 103 dimension matrix.</p>
  <p>This is what I tried in Python:</p>
  <pre class="lang-py prettyprint-override"><code>for j in range(np.int64(n)):
      for i in range(np.int64(m)): 
          a= -np.mat(4)*np.mat(f)*np.mat(d[:i])
          b=np.log((NormPS[i,j] [(d).astype(int)]).reshape(-1,1))
          #check=(d[:i])
  </code></pre>
  <p>I am getting the same result for the log part of the Matlab which is b in my python code. However, for the sum part I am getting this error<code>error : shapes (1,441) and (0,103) not aligned: 441 (dim 1) != 0 (dim 0)</code></p>
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last): 
  File ~\Desktop\spyder_files\2D_spyder_file\algebra_2D_spyder.py:48 in &lt;module&gt; a= -np.mat(4)*np.mat(f)*np.mat(d[:i])
  File ~\anaconda3\lib\site-packages\numpy\matrixlib\defmatrix.py:218 in mul return N.dot(self, asmatrix(other))
  File &lt;__array_function__ internals&gt;:5 in dot ValueError: shapes (1,441) and (0,103) not aligned: 441 (dim 1) != 0 (dim 0)
  </code></pre>
  <p>Is there any way I can rewrite <code>a=sum(-4*f*d(i))</code>? I am sure the error is in <code>d(i)</code>.</p>