Array.permute<'T> Function (F#)
Returns an array with all elements permuted according to the specified permutation.
Namespace/Module Path: Microsoft.FSharp.Collections.Array
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
Array.permute : (int -> int) -> 'T [] -> 'T []
// Usage:
Array.permute indexMap array
Parameters
-
The function that maps input indices to output indices.
array
Type: 'T []The input array.
Return Value
The permuted array.
Remarks
This function is named Permute in compiled assemblies. If accessing the function from a language other than F#, or through reflection, use this name.
Example
The following code illustrates the use of Array.permute.
let printPermutation n array1 =
let length = Array.length array1
if (n > 0 && n < length) then
Array.permute (fun index -> (index + n) % length) array1
else
array1
|> printfn "%A"
let array1 = [| 1 .. 5 |]
// There are 5 valid permutations of array1, with n from 0 to 4.
for n in 0 .. 4 do
printPermutation n array1
Output
[|1; 2; 3; 4; 5|] [|5; 1; 2; 3; 4|] [|4; 5; 1; 2; 3|] [|3; 4; 5; 1; 2|] [|2; 3; 4; 5; 1|]
Platforms
Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3
See Also
Reference
Microsoft.FSharp.Collections Namespace (F#)
Change History
Date |
History |
Reason |
---|---|---|
May 2010 |
Added code example. |
Information enhancement. |