16

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
Patrick
  • 17,168
  • 6
  • 69
  • 83
JerryKur
  • 6,809
  • 6
  • 23
  • 31

2 Answers2

8

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

Icemanind
  • 45,770
  • 48
  • 167
  • 283
  • 2
    This link points to the original PTVS project. PTVS never (really) implemented numpy and is outdated now. The only project which gets close to numpy on .NET is [ILNumerics](https://ilnumerics.net) – user492238 Nov 04 '18 at 09:27
1

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>.

Community
  • 1
  • 1
driis
  • 156,816
  • 44
  • 266
  • 336