I'm trying to do an inline uniform distribution initialization, but don't seems to find how to do so, if possible.
My working code is:
test = [[1,2,3],[4,5,6],[7,8,9]]
p = []
for row in test:
prow = [1.0/(len(row)*len(test)) for x in row]
p.append(prow)
print p
[[0.1111111111111111, 0.1111111111111111, 0.1111111111111111],
[0.1111111111111111, 0.1111111111111111, 0.1111111111111111],
[0.1111111111111111, 0.1111111111111111, 0.1111111111111111]]
My question is, is there a way to narrow the "for row in test" to the same form of the second loop and end up with only 1 line? Something like:
p = [1.0/(len(row)*len(test)) for x in row for row in test]
print p
[0.1111111111111111,
0.1111111111111111,
0.1111111111111111,
0.1111111111111111,
0.1111111111111111,
0.1111111111111111,
0.1111111111111111,
0.1111111111111111,
0.1111111111111111]
But obviously the right result. Clues?