Using Array.map in an Array of Arrays

I have an array of P arrays representing the matrix as an array of row vectors (this representation is more convenient for my purposes), and I want to extract the column vector j of this array. My first pass was:

let column (M: float[][]) (j: int) =
   Array.map(fun v -> v.[j]) M

This does not compile telling me that v. [j] uses the expr operator. [idx] for an object of undefined type. This puzzles me, because the hovering v recognizes v as a float [], which I believe is a row vector.

In addition, the following code works:

let column (M: float[][]) (j: int) =
   Array.map(fun v -> v) M
   |> Array.map (fun v -> v.[j])

I do not understand how the second example is different from the first. The first map in the second example looks redundant: I map the array to myself, and yet it seems to solve the type determination problem.

Any help understanding what I am doing wrong or don’t see will be greatly appreciated!

+3
2

, F # ,

let column (M: float[][]) (j: int) =
   Array.map(fun v -> v.[j]) 

v, . |> - ​​

let column (M: float[][]) (j: int) =
   M |> Array.map(fun v -> v.[j]) 

.

+5

, v , M - . :

let column (M: float[][]) (j: int) =
   M |> Array.map (fun v -> v.[j])

let column M (j: int) =
   Array.map (fun (v: float []) -> v.[j]) M

.

fun v -> v . , . |> , , , .

+3

All Articles