gpt4 book ai didi

F# 计算基于 Sequence 先前值的函数

转载 作者:行者123 更新时间:2023-12-05 01:30:07 24 4
gpt4 key购买 nike

我想获得包含计算值 (xi-xi-1)/x i-1 的新序列。没有 for 语句怎么办?

let GAZP = seq  [ 183.24; 170.15;174.17;170.67;170.15;171.2;172.56;178.1;191.5;190.5;175.1]

let gazpReturnRate =
GAZP
|> Seq.skip 1
|> Seq.map(fun x -> x)

printf "%A" gazpReturnRate

最佳答案

使用Seq.pairwise .它创建了所有连续对的序列:

GAZP
|> Seq.pairwise
|> Seq.map (fun (xn_1, xn) -> (xn - xn_1) / xn_1)

关于F# 计算基于 Sequence 先前值的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46875644/

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