ranking

Rank and unrank permutations with just one cycle

三世轮回 提交于 2021-02-17 02:04:55
问题 I want to rank and unrank permutations with one cycle in lexicographical order with a given len. A permutation with one cycles is where you can visit in this cycle each element. p:= (2,3,1) is a permutation with one cycle. Has rank 1. p:= (3,1,2) has 1 cycle too, but rank 2, because the permutation is lexicographical greater the frist so it becomes a greater rank. p:= (1,2,3) is a permutation with 3 cycles. (1),(2),(3) How can I efficently rank (permutation with one cycle to rank) and unrank

How to rank a vector using a second vector as a tie breaker?

自作多情 提交于 2021-02-05 06:41:28
问题 I need to implement a ranking algorithm for numeric vectors. I don't know if it's possible to do it using functions like rank(), order() or sort() in R, or if I should hard-code it. Either way, I could not do it. The algorithm works as follows: Let x = (x_1,x_2...,x_n) and y = (y_1,y_2,...y_n) be two vectors. We need to build the vector z composed of the ranked elements of x this way: If x_i < x_j then z_i < z_j If x_i = x_j then z_i < z_j if y_i < y_j z_i > z_j if y_i > y_j z_i = z_j if y_i

Oracle SQL conditional ranking

断了今生、忘了曾经 提交于 2021-01-28 09:51:14
问题 In my query, I am doing multiple types of ranking and for one of ranking types, I want to rank the row only if certain column is not null. Else I don't want ranking to happen. For example here's a sample table: +------+------------+------------+--------+--------+ | col1 | col2 | col3 | rank 1 | rank 2 | +------+------------+------------+--------+--------+ | a | 2018-01-20 | 2018-03-04 | 2 | 2 | | a | 2018-01-24 | 2018-04-04 | 1 | 1 | | b | 2018-01-02 | 2018-05-03 | 1 | 1 | | c | 2017-01-02 |

Oracle SQL conditional ranking

泪湿孤枕 提交于 2021-01-28 09:46:43
问题 In my query, I am doing multiple types of ranking and for one of ranking types, I want to rank the row only if certain column is not null. Else I don't want ranking to happen. For example here's a sample table: +------+------------+------------+--------+--------+ | col1 | col2 | col3 | rank 1 | rank 2 | +------+------------+------------+--------+--------+ | a | 2018-01-20 | 2018-03-04 | 2 | 2 | | a | 2018-01-24 | 2018-04-04 | 1 | 1 | | b | 2018-01-02 | 2018-05-03 | 1 | 1 | | c | 2017-01-02 |

Numpy Array Rank All Elements

 ̄綄美尐妖づ 提交于 2021-01-27 18:50:23
问题 I have a two-dimensional numpy array and I am wondering how I can create a new two-dimensional numpy array represent the ranking of the values based on all items in the original 2d array. I would like to use the following array : anArray = [[ 18.5, 25.9, 7.4, 11.1, 11.1] [ 33.3, 37. , 14.8, 22.2, 25.9] [ 29.6, 29.6, 11.1, 14.8, 11.1] [ 25.9, 25.9, 14.8, 14.8, 11.1] [ 29.6, 25.9, 14.8, 11.1, 7.4]] to create a new rank ordered array [based on all values and having same rank for multiple numbers

Using LIMIT within GROUP BY to get N results per group?

假装没事ソ 提交于 2021-01-05 13:20:52
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

Using LIMIT within GROUP BY to get N results per group?

痴心易碎 提交于 2021-01-05 13:20:38
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

Using LIMIT within GROUP BY to get N results per group?

好久不见. 提交于 2021-01-05 13:19:50
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

Using LIMIT within GROUP BY to get N results per group?

試著忘記壹切 提交于 2021-01-05 13:19:30
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

How can I save SortableJS positions to an object? [duplicate]

心不动则不痛 提交于 2020-12-13 03:35:18
问题 This question already has answers here : Convert Array to Object (45 answers) Closed 18 days ago . I am trying to create a questionnaire where users rank images from favourite to least. I am using the SortableJS so the images can be dragged and dropped. I have the position of the images currently in the console.log. However, I am trying to push it to a dictionary so it could be formatted as: {0 : image2, 1:image1, 2:image3} . This would allow me to see what image is at each index, so when the