Is there a c# library that provides array manipula

2020-08-10 09:28发布

I am starting to use the Numpy and really like it's array handling capabilities. Is there some library that I can use in C# that provides similar capabilities with arrays. The features I would like most are:

  • Creating one array from another
  • Easy/trival iteration of arrays of n dimension
  • Slicing of arrays

标签: c# arrays numpy
2条回答
我想做一个坏孩纸
2楼-- · 2020-08-10 09:56

NumPY has been ported to .NET via IronPython. Look here for the home page.

查看更多
欢心
3楼-- · 2020-08-10 10:03

I don't think you need a library. I think LINQ does all you mention quite well.

Creating one array from another

int[,] parts = new int[2,3];

int[] flatArray = parts.ToArray();
// Copying the array with the same dimensions can easily be put into an extension 
// method if you need it, nothing to grab a library for ...

Easy iteration

int[,] parts = new int[2,3];

foreach(var item in parts)
    Console.WriteLine(item);

Slicing of arrays

int[] arr = new int[] { 2,3,4,5,6 };
int[] slice = arr.Skip(2).Take(2).ToArray();

// Multidimensional slice 
int[,] parts = new int[2,3];
int[] slice = arr.Cast<int>().Skip(2).Take(2).ToArray();

The awkward .Cast<int> in the last example is due to the quirk that multidimensional arrays in C# are only IEnumerable and not IEnumerable<T>.

查看更多
登录 后发表回答