How to write a matlab function in Python?
4 views (last 30 days)
I'm trying to transform a for loop from Matlab into python. I would like to create arrays of zeros and fill them via a for loop. In Matlab everything works perfectly, but in Python I have some problems The cycle is as follows:
A = zeros(3,Nrs,Ncs);
B = zeros(3,3,Nrs,Ncs);
C = zeros(3,3,Nrs,Ncs);
D = zeros(12,Nrs,Ncs);
[a b c d]= my_function(pos)
This is my convertion in Python:
import numpy as np
for j in range(0,column_D,step):
for i in range(0,row_D,step):
%write the function here
Up to here everything works, but I can't write the function and fill my arrays A e B like on Matlab. Could anyone help me?
Al Danial on 15 Dec 2022
You didn't show what my_function() looks like. Aside from that, the notation for populating A and B in NumPy is the same as in matlab, except you need to use brackets instead of parentheses: