How to keep some columns and rows of jagged array and remove unwanted columns and rows in c# -
i have following jagged array
int[][] dists1 = new int[][] { new int[]{0,2,3,5,2,4}, new int[]{2,0,1,3,5,3}, new int[]{3,1,0,4,4,3}, new int[]{5,3,4,0,2,4}, new int[]{2,5,4,2,0,2}, new int[]{4,3,3,4,2,0} };
and learned how delete 1 specific column , row (for example 3). here's a link.
now want have dynamic programming follows: consider array
int[] day={1,4,5};
this array can array (i used dynamic term reason)
where elements of array "day" shows "dists1" matrix rows , columns, want new jagged array named " dists2" contains columns , rows of 1,4,5 with row , column "0" because fixed row , column follow:
int[][] dists2 = new int[][] { new int[]{0,2,2,4}, new int[]{2,0,5,3}, new int[]{2,5,0,2}, new int[]{4,3,2,0} };
simply modify that answer , replace != 2 condition contains method of day array:
int[] day = {1,4,5}; int[][] finaldists = dists.where((arr, i) => == 0 || day.contains(i)) //skip rows .select(arr=> arr.where((item, i) => == 0 || day.contains(i)) //skip cols .toarray()) .toarray();
anyway if performance matters, way better use loops instead of linq.
Comments
Post a Comment