Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map-summing items in a multidimensional array
- [ (0.5, 0.6, 0.7), (0.1, 0.9, 0.8), (0.9, 1.0, 0.4),
- ...
- (0.3, 0.8, 0.3), (0.2, 0.4, 0.9), (0.5, 0.5, 0.3) ]
- >>> c=[ (0.5, 0.6, 0.7), (0.1, 0.9, 0.8), (0.9, 1.0, 0.4),(0.5, 0.6, 0.7), (0.1, 0.9, 0.8), (0.9, 1.0, 0.4),(0.5, 0.6, 0.7), (0.1, 0.9, 0.8), (0.9, 1.0, 0.4)]
- >>> [ sum([t[i] for t in c]) for i in range(len(c[0]))]
- [4.5, 7.5, 5.6999999999999993]
- result = reduce(lambda x, y: tuple((xi + yi) for (xi, yi) in zip (x, y)), l)
- >>> reduce(lambda x, y: (x[0]+y[0], x[1]+y[1], x[2]+y[2]), [(1, 2, 3), (2, 3, 4), (4, 5, 6)])
- (7, 10, 13)
- values = [(1,2,3), (4,5,6)]
- print map(sum, values)
Advertisement
Add Comment
Please, Sign In to add comment