Seq.windowed<'T> 函数 (F#)

返回一个序列,用于生成容纳从输入序列中提取的元素的滑动窗口。 每个窗口都以新数组的形式返回。

命名空间/模块路径: Microsoft.FSharp.Collections.Seq

程序集:FSharp.Core(在 FSharp.Core.dll 中)

// Signature:
Seq.windowed : int -> seq<'T> -> seq<'T []>

// Usage:
Seq.windowed windowSize source

参数

  • windowSize
    类型:int

    每个窗口中的元素数。

  • source
    类型:seq<'T>

    输入序列。

异常

异常

Condition

ArgumentException

在输入序列为空时引发。

ArgumentNullException

在输入序列为 null 时引发。

返回值

结果序列。

备注

此函数在编译的程序集中名为 Windowed。 如果从 F# 以外的语言中访问函数,或通过反射访问成员,请使用此名称。

示例

以下示例演示如何将 Seq.windowed 作为数列移动平均计算的一部分来使用。

let seqNumbers = [ 1.0; 1.5; 2.0; 1.5; 1.0; 1.5 ] :> seq<float>
let seqWindows = Seq.windowed 3 seqNumbers
let seqMovingAverage = Seq.map Array.average seqWindows
printfn "Initial sequence: "
printSeq seqNumbers
printfn "\nWindows of length 3: "
printSeq seqWindows
printfn "\nMoving average: "
printSeq seqMovingAverage
  

平台

Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2

版本信息

F# 运行时

受以下版本支持:2.0、4.0

Silverlight

受以下版本支持:3

请参见

参考

Collections.Seq 模块 (F#)

Microsoft.FSharp.Collections 命名空间 (F#)