我有一个元组的元组:
nums = ((4, 5, 6), (5, 6, 7), (2, 3))
现在我想创建一个类似的结构,其中每个数字都从“基线”数字中减去。元组的基线数是:
baselines = (1, 0.5, 3)
所以我想要的结构是:
# want: diffs = ((3, 4, 5), (4.5, 5.5, 6.5), (-1, 0))
我们有:
diffs[0] = [x - baselines[0] for x in nums[0]]
diffs[1] = [x - baselines[1] for x in nums[1]]
# etc.
如何在 Python 中优雅地做到这一点?