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

查看:43
本文介绍了计算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#中序列的后续元素的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆