I am new to programming and trying to learn from application. I have a function in python:
def eps(u):
return as_vector([u[i].dx(i) for i in range(3)] + [u[i].dx(j) + u[j].dx(i) for i, j in [(0, 1), (0, 2), (1, 2)]])
I understand that in the above function, the statement i in range(3)
is going to run a loop for u[0].dx(0)....u[2].dx(2)
but I don't understand the for i, j in [(0, 1), (0, 2), (1, 2)]])
part. How is this entire statement going to execute? Can someone pls. explain.
Similarly I have:
def tangent(t):
return as_matrix([[t[i*6 + j] for j in range(6)] for i in range(6)])
I believe the expression t[i*6 + j]
will run 6 times for i = 0:5 and for each value of 'i', we will have 'j = 0:5'. Hence, I will get a 6x6 matrix. Is that correct?