编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

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

腾讯云服务器
计算F#中序列的后续元素的差异的处理方法

我在F#中有一个浮点数序列,我需要获得一个定义为(Math.Log currentElement)/(Math.Log previousElement)的序列.显然,它将比原始序列短一个元素.

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.

在F#中实现这一目标的最优雅的方法是什么?我当时想在内部使用带for循环的seq {}表达式,但是即使那样,以一种相当不错的方式处理第一个元素似乎还是困难的……

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) 

这篇关于计算F#中序列的后续元素的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^