Cálculo de diferencias de elementos posteriores de una secuencia en 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...

preguntado el 28 de agosto de 12 a las 15:08

2 Respuestas

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

Respondido 28 ago 12, 15:08

O si lo prefieres:

let f (x, y) = (log y) / (log x)

let ans = s |> Seq.pairwise |> Seq.map f

Respondido 28 ago 12, 22:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.