###### 编程技术网

 用户名 Email 自动登录 找回密码 密码 立即注册

# 计算F#中序列的后续元素的差异:Calculating differences of subsequent elements of a sequence in F#

crendy 序列 2022-5-11 19:30 6人围观

I have a sequence of floats in F#, and I need to get a sequence defined of (Math.Log currentElement)/(Math.Log previousElement). Obviously it will be shorter than the original sequence by one element.

What is the most elegant way to achieve this in F#? I was thinking to use a seq{} expression with a for loop inside, but even then handling the first element in a reasonably nice way seems difficult...

### 问题解答

items |> Seq.pairwise |> Seq.map (fun (x, y) -> log y / log x) 

^