sorting

Sorting 2D array in new 2D array (K-menas clustering) Java

ε祈祈猫儿з 提交于 2020-07-22 06:09:41
问题 As input I have 2D array PointXY[ ][ ] clusters, which looks like this: [[23.237633,53.78671], [69.15293,17.138134], [23.558687,45.70517]] . . . [[47.851738,16.525734], [47.802097,16.689285], [47.946404,16.732542]] [[47.89601,16.638218], [47.833263,16.478987], [47.88203,16.45793]] [[47.75438,16.549816], [47.915512,16.506475], [47.768547,16.67624]] . . . So elements in array are of type PointXY[ ], defined like this public PointXY(float x, float y) { this.x = x; this.y = y; } what I would like

Bitonic sorting in cuda misorders some values

旧巷老猫 提交于 2020-07-19 13:47:25
问题 i'm making a sorting algorithm on CUDA for a bigger project and i decided implementing a Bitonic sorting. The number of elements i'll be sorting will be allways a power of two, in fact will be 512. I need an array which will have the final positions because this method will be used for ordering an array that represents the quality matrix of another solution. fitness is the array i'll sort, numElements is the number of elements, and orden is initially an empty array with numElements positions

MYSQL order by text

╄→гoц情女王★ 提交于 2020-07-19 04:25:29
问题 okay so I know how I can sort by id or number like $getTicket = $sql->query("SELECT * FROM `ticket` WHERE `user`='$user->name' ORDER BY `id` DESC"); I have Status in the ticket table, and in that I have 3 things: 1) Answered 2) Unanswered 3) Done I want to sort it in this way: 1) Unanswered 2) Answered 3) Done is there a way to do this? 回答1: Do simple as- ORDER BY FIELD(Status, 'Unanswered', 'Answered', 'Done') 回答2: You can generally use case SELECT * FROM `ticket` WHERE `user` = '$user->name

Sort Structured Numpy Array On Multiple Columns In Different Order

时光毁灭记忆、已成空白 提交于 2020-07-18 22:26:28
问题 I have a structured numpy array: dtype = [('price', float), ('counter', int)] values = [(35, 1), (36, 2), (36, 3)] a = np.array(values, dtype=dtype) I want to sort for price and then for counter if price is equal: a_sorted = np.sort(a, order=['price', 'counter'])[::-1] I need the price in a descending order and when prices are equal consider counter in ASCENDING order. In the example above both the price and the counter are in descending order. What I get is: a_sorted: [(36., 3), (36., 2),

dask set_index from large unordered csv file

别来无恙 提交于 2020-07-18 18:40:27
问题 At the risk of being a bit off-topic, I want to show a simple solution for loading large csv files in a dask dataframe where the option sorted=True can be applied and save a significant time of processing. I found the option of doing set_index within dask unworkable for the size of the toy cluster I am using for learning and the size of the files (33GB). So if your problem is loading large unsorted CSV files, ( multiple tens of gigabytes ), into a dask dataframe and quickly start performing

How to sort structure arrays in MATLAB?

血红的双手。 提交于 2020-07-17 10:15:13
问题 I'm working with an image retrieval system using color histogram intersection in MATLAB. This method gives me the following data: a real number which represents the histogram intersection distance, and the image file name. Because they are different data types, I store them in structure array with two fields, and then I save this structure in a .mat file. Now I need to sort this structure according to the histogram intersection distance in descending order in order to retrieve the image with

Given an array of integers, find the first missing positive integer in linear time and constant space

百般思念 提交于 2020-07-17 05:41:10
问题 In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. This question was asked by Stripe in it's programming interview. I have devised a solution for the same as below: #include<bits/stdc++.h> using namespace std; int main(){ int arr[]={1,-1,-5,-3,3,4,2,8}; int size= sizeof(arr)/sizeof(arr[0]); sort(arr, arr+size); int min=1; for(int i=0; i<size; i++){ if(arr[i]>min) break; if(arr[i]==min) min=min+1; }

Python Memory Error when reading large files , need ideas to apply mutiprocessing in below case?

守給你的承諾、 提交于 2020-07-16 04:22:46
问题 I have the file which stores the data in the below format TIME[04.26_12:30:30:853664]ID[ROLL:201987623]MARKS[PHY:100|MATH:200|CHEM:400] TIME[03.27_12:29:30.553669]ID[ROLL:201987623]MARKS[PHY:100|MATH:1200|CHEM:900] TIME[03.26_12:28:30.753664]ID[ROLL:2341987623]MARKS[PHY:100|MATH:200|CHEM:400] TIME[03.26_12:29:30.853664]ID[ROLL:201978623]MARKS[PHY:0|MATH:0|CHEM:40] TIME[04.27_12:29:30.553664]ID[ROLL:2034287623]MARKS[PHY:100|MATH:200|CHEM:400] Below method I found to fulfill the need given in

Using Quick Sort in C to sort in reverse direction (descending)?

五迷三道 提交于 2020-07-15 08:23:21
问题 To sort I call qsort(myArray,100,sizeof(int), comp) int comp(const int * a, const int * b) if(a==b) { return 0; } else { if(a<b) { return -1; } else { return 1; } } First, This doesn't really work, when I sort an array (9,8,7,6,5,4,3,2,1,1), I get (4,8,7,6,5,9,3,2,1) - NOT really sorted. Second, How would I sort in the other direction? Is there a special flag for qsort I need to pass? 回答1: Change your compare function so that it is ordering the way you like. And the compare function takes

remove entirely same duplicate columns in unix

瘦欲@ 提交于 2020-07-10 10:42:45
问题 Let say I have a file as below: number 2 6 7 10 number 6 13 name1 A B C D name1 B E name2 A B C D name2 B E name3 B A D A name3 A F name4 B A D A name4 A F I wish to remove the entirely the same duplicate columns and the output file is as below: number 2 6 7 10 13 name1 A B C D E name2 A B C D E name3 B A D A F name4 B A D A F I use sort and uniq command for lines but never know how to do for columns. Can anyone suggest a good way? 回答1: Here is a way with awk that preserves the order awk 'NR=