Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating differences of subsequent elements of a sequence in F#

Tags:

f#

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...

like image 239
Grzenio Avatar asked Jan 15 '23 17:01

Grzenio


1 Answers

items |> Seq.pairwise |> Seq.map (fun (x, y) -> log y / log x)
like image 59
Daniel Avatar answered Feb 02 '23 19:02

Daniel