pythonc#numpymathnet-numerics

Is there a equivalent of the numpy.tile() function in C#?


I'm trying to use a alternative for numpy.tile() in C# to copy an array n times to create a matrix of this array. Maybe it can be found in the MathNet.Numerics.LinearAlgebra library, but I can't find anything.


Solution

  • If you have an array A B C:

    var a = new []{"a","b","c"};
    

    And you want a 10 element array that is ABCABCABCA:

    var ten = Enumerable.Range(0, 10).Select(n => a[n%a.Length]).ToArray();
    

    Or you want a 3x4 array:

    var tbf = Enumerable.Range(0, 4).Select(n => (string[])a.Clone()).ToArray();
    

    Note that this isn't a C# version of tile, it's using LINQ to arrange something similar to the aspects of tile, as far as I can understand, that you might want..