c# - Sort 2D array based on user provided indices -


in python there functionality (numpy.take) sort arrays within array, example if have array (3x3):

a = [[1, 2, 3],[7,9,10],[3, 5,6]]  

and have array of set indices

indices = [2, 0, 1] 

the result shall

array([[ 3,  5,  6], [ 1,  2,  3], [ 7,  9, 10]]). 

are there direct approach methods/ functions these in c# can pass in jagged array , produce same output?

not directly, can achieve same thing linq

var = new[] { new[] { 1, 2, 3 }, new[] { 7, 9, 10 }, new[] { 3, 5, 6 } }; var indices = new [] { 2, 0, 1 }; var sorted = indices.select(i => a[i]).toarray(); foreach(var s in sorted) console.writeline(string.join(", ", s)); 

note not check indices in range.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -