mercredi 4 avril 2018

Python: Complex for-loops

I am working through some code trying to understand some Python mechanics, which I just do not get. I guess it is pretty simple and I also now, what it does, but i do not know how it works. I understand the normal use of for-loops but this here... I do not know.

Remark: I know some Python, but I am not an expert.

np.array([[[S[i,j]] for i in range(order+1)] for j in range(order+1)])

The second piece of code, I have problems with is this one:

for i in range(len(u)):
        for j in range(len(v)):
            tmp+=[rm[i,j][k]*someFuction(name,u[i],v[j])[k] for k in range(len(rm[i,j])) if rm[i,j][k]]

How does the innermost for-loop work? And also what does the if do here?

Thank you for your help.

Aucun commentaire:

Enregistrer un commentaire