我有一个数字列表,我想从中返回尾数列表:

get_mantissa([1.565888, 2.073744, 2.962492, 4.52838, 5.417127, 7.025337])
#[0.565888, 0.073744, 0.962492, 0.52838, 0.417127, 0.025337]

所有帮助,不胜感激。

最佳答案

您可以使用所有数字mod 1:

>>> l = [1.565888, 2.073744, 2.962492, 4.52838, 5.417127, 7.025337]
>>>
>>> [a%1 for a in l]
[0.565888, 0.07374400000000003, 0.9624920000000001, 0.5283800000000003, 0.4171269999999998, 0.025337000000000387]

如果您还将处理底片,那么a - int(a)应该这样做:
>>> [a - int(a) for a in l]  # works with negatives too
[0.565888, 0.07374400000000003, 0.9624920000000001, 0.5283800000000003, 0.4171269999999998, 0.025337000000000387]

10-04 21:06