4
Sort the 2D table according to user-supplied clues
source link: https://www.codesd.com/item/sort-the-2d-table-according-to-user-supplied-clues.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Sort the 2D table according to user-supplied clues
advertisements
In python there is a functionality (numpy.take) to sort arrays within an array, for example if I have an array (3x3):
a = [[1, 2, 3],[7,9,10],[3, 5,6]]
and I have an array of set indices
indices = [2, 0, 1]
the result shall be
array([[ 3, 5, 6], [ 1, 2, 3], [ 7, 9, 10]]).
Are there any direct approach methods/ functions as these in C# where I can pass in a jagged array and produce the same output?
Not directly, but you can achieve the same thing with Linq
var a = 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 this does not check that your indices are all in range.
Tags
sorting
Related Articles
Group or sort the list / table according to the number of corresponding keywords
What's a good, efficient way in C# to group or sort the elements of a string array or List by the number of matching keywords between each & every element. Elements with most matching keywords should be placed near each other. For example, if the col
sorting the CSS table according to the different topics in the table - a problem with previous questions asked
this is the earlier asked question css table sorting based on different headings in the table and this was the accepted solution. $("#<ID_OF_YOUR_TABLE").dataTable(); and here is the working fiddle with solution. http://jsfiddle.net/wxaXD/ no
Sort the input table according to another group of entries
Supposed I have two arrays, like this: var SortedArray = [25, 123, 2464, 112, 54, 51, 347, 4572, 634]; var ArrayToSort = [634, 25, 51, 123]; SortedArray is an array that contains the order of many elements. ArrayToSort contains just some of the eleme
Sort the whole table according to the custom comparator
This is something simple but I'm obviously missing something.... I have a 2D array that contains integer representations of Color values that have been calculated from a BufferedImage object. I also have a method to calculate the brightness value bas
Sort the hash table according to the value of the key in the hash?
I'm attempting to work with Vagrant to perform some automation in spinning up Docker containers. Vagrantfiles are essentially Ruby and thus I should be able to apply Ruby logic to assist with this issue. I am reading through a conf.d directory filled
Sort the JSON table alphabetically and by value on a second level
I want to sort the jJSON table alphabetically AND on a second level by the value of data.fuelState (float). I managed to get the alphabetically sorting done (thanks stackoverflow :)) .. How has this to be done? <!DOCTYPE html> <html> <head&
How to sort the html elements according to the values in the table
I am trying to sort html elements with jQuery based off the order of items in a data attribute on an input. "data-order" See the code setup here, but I am stuck. http://jsbin.com/cixolonoqe/1/edit?html,js,output HTML: <div id="control&qu
Sort the list in the hash table according to specific comparison criteria in R
I am looking for a way, in R, to convert a list into a hash table, grouping elements that are similar according to a specific criteria. The details are specific to "graph theory", as explained bellow, but I suppose the answer is a general proced
How to sort the FTPFile [] table object according to the timestamp in java
I am polling files from FTP server. I have an use case to sort the array FTPFile[] based on timestamp. I want to first modified file as first object and last modified file as last object in my FTPFile[] array object. Can some one please suggest me ho
Sort the SQL table with the values from another table
I have an SQL table(tblRequests) with the list of requests submitted by different users. The fields are: RequestID, UserID, DateSubmitted, Status I have another table(tblImportantUsers) with the list of important users. This table has only one field
Sort the postgres table data into the php table
I have a postgres database with a table called workorders. In it is a column called date_out where the date is recorded like 2009-09-23. I want to sort this table data in a php page based on a users date range, ie, sort the table by date begin 2009-0
Sort the mysql array according to the number of rows in another array
I'm trying to sort a user table based on how many comments they have linked to them in a secondary comment-table, I figured a sub-select will be the best tool but I can't get the syntax correct. Users table testdata: id | user_id 1 | 1000 2 | 1001 3
Sorting the html table with sql-query data by clicking on the name of the field
I have an sql-database, where data can be read out by an html-form. The data are shown in an html-table, this works fine! However, I would like to make the table sortable, which means, that by clicking on the respective field-name the data should be
How to sort the following objects accordingly? (Array, ArrayList, Comparable)
I finally understood the various possibilities of Comparable from java.util.Collections; I can order an object, for example "Beer" with attributes float content, String name and String origin in any order that I want, combining them how I want.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK