I have part of a code that does something analogous to the following:
import numpy as np
N = 10
test = [1] * N
np.random.seed(123)
norm = np.random.rand(N)
my_dic = {(k, kk):np.random.rand(1) for k,_ in enumerate(test) for kk in range(5)}
for i, _ in enumerate(test):
test[i] *= norm[i]
for j in range(5):
test[i] *= my_dic[(i, j)]
Since both loop are modifying a list, is there a way for me to translate that to list comprehension? I have been trying variations of the following, with no success:
import numpy as np
N = 10
test = [1] * N
np.random.seed(123)
norm = np.random.rand(N)
my_dic = {(k, kk):np.random.rand(1) for k,_ in enumerate(test) for kk in range(5)}
test = [val for val in norm]
test = [test[i] * my_dic[(i, j)] for i, _ in enumerate(test) for j in range(5)]