Speed up double loop in Python
问题 Is there a way to speed up a double loop that updates its values from the previous iteration? In code: def calc(N, m): x = 1.0 y = 2.0 container = np.zeros((N, 2)) for i in range(N): for j in range(m): x=np.random.gamma(3,1.0/(y*y+4)) y=np.random.normal(1.0/(x+1),1.0/sqrt(x+1)) container[i, 0] = x container[i, 1] = y return container calc(10, 5) As you can see, the inner loop is updating variables x and y while the outer loop starts with a different value of x each time. I don't think this is