Unusual list comprehension behaviour
问题 I'm trying to port some code from Python to R and I've come across a list comprehension I cannot fully understand. Here is a toy example analogous to the code import numpy as np theta = np.random.rand(5, 2, 2, 3) thetai = theta[0] logp = [theta[np.newaxis, ...] for theta in thetai] If I run and print the results I get: print(logp) [array([[[0.779, 0.461, 0.766], [0.245, 0.189, 0.045]]]), array([[[0.229, 0.288, 0.173], [0.011, 0.541, 0.528]]])] Ok output is a list of two arrays. What I cannot