Issue
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
Solution
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>
.
Answered By - driis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.