简体   繁体   English

F#中的数组串联

[英]array concatenation in F#

Are there any analogs to Matlab's horzcat () and vertcat () functions in F#? F#中是否有与Matlab的horzcat ()和vertcat ()函数类似的东西 Because what I'm doing now seems asinine. 因为我现在正在做的事情看起来很愚蠢。 There is a related question here but it seems pretty dated. 这里有一个相关的问题但似乎过时了。

    let arr = Array.init 5 (fun i -> 1.)
    let xMat = DenseMatrix.init l 2 (fun r c -> if c = 0 then 1. else arr.[r])

There is an Array.concat but it seems to work only vertically. 有一个Array.concat,但它似乎只能垂直工作。

As far as I know, there is no built-in function to do this for F# arrays , but in your code you are ultimately working with matrices from Math.NET Numerics and Math.NET has functions to append matrices vertically and horizontally: 据我所知,没有内置函数可以对F# 数组执行此操作,但是在您的代码中,最终您将使用Math.NET Numerics中的矩阵 ,而Math.NET具有在垂直和水平方向上附加矩阵的功能:

let m1 = DenseMatrix.init 5 1 (fun _ _ -> 1.)
let m2 = DenseMatrix.init 5 1 (fun _ _ -> 2.)

DenseMatrix.append [m1; m2] // Append matrices horizontally
DenseMatrix.stack [m1; m2]  // Append matrices vertically

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM