【问题标题】:Modifying values in list in Python在 Python 中修改列表中的值
【发布时间】:2020-05-13 14:44:13
【问题描述】:

我有一个 [(x1, y1), (x2, y2), (x3, y3)] 形式的列表

test = [(5, 3.7357663e-01), (10, 1.2537051e-01), (15, 6.7936250e-02)]

我正在尝试对 y 值进行计算:自然 log(y)

导致

test = [(5, -0.9846321281171939), (10, -2.076481845903636), (15, -2.6891855135340066)]

我该怎么做?

【问题讨论】:

    标签: python list numpy


    【解决方案1】:

    使用列表推导。

    import numpy as np
    
    test1 = [(x, np.log(y)) for x, y in test]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      • 1970-01-01
      • 2019-07-18
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多