是否有一个C#库提供像numpy这样的数组操作 [英] Is there a c# library that provides array manipulation like numpy
本文介绍了是否有一个C#库提供像numpy这样的数组操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始使用Numpy,非常喜欢它的数组处理功能.我可以在C#中使用一些库来为数组提供类似的功能.我最想要的功能是:
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:
- 从另一个阵列创建一个阵列
- n维数组的简单/遍历迭代
- 切片数组
推荐答案
我认为您不需要图书馆.我认为LINQ可以很好地提及您.
I don't think you need a library. I think LINQ does all you mention quite well.
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 ...
轻松迭代
int[,] parts = new int[2,3];
foreach(var item in parts)
Console.WriteLine(item);
数组切片
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();
最后一个示例中的尴尬.Cast<int>
是奇怪的是,C#中的多维数组只是IEnumerable
而不是IEnumerable<T>
.
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>
.
这篇关于是否有一个C#库提供像numpy这样的数组操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文