gpt4 book ai didi

python - Pandas/Numpy 中的迭代公式

转载 作者:行者123 更新时间:2023-12-01 09:27:45 25 4
gpt4 key购买 nike

是否可以使用 Pandas 和 Numpy 执行迭代/递归计算?也就是说,使用 Numpy 函数消耗 DataFrame 中的数据并有效应用公式,而不是使用 Python for 循环逐步进行计算。

例如,斐波那契数列看起来如何?

Iterative Fibonacci

最佳答案

任何常数系数线性递推都有一个封闭形式的解(有 many methods of finding them )。具体来说,对于您来说,它是 given by the following one :

import numpy as np

x = np.array(range(10))
>>> np.array(((1 + np.sqrt(5))**x - (1 - np.sqrt(5))**x) / (2**x * np.sqrt(5)), dtype=int)
array([ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34])

关于python - Pandas/Numpy 中的迭代公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50229388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com