1

I am trying to get a rank of worst case scenarios but there are two different types of worst case scenarios that I am trying to compare. So I have two separate arrays and I am trying to compare them to one another.

I used the sorting method from the link below and it works when sorting with one array but not with two.

Rank items in an array using Python/NumPy, without sorting array twice

CI_SUM_1 = numpy.array([2,1,7,23])
CI_SUM_2 = numpy.array([4,0,22,3])
order = CI_SUM_1.argsort() + CI_SUM_2.argsort() 
rank = order.argsort()
print(rank)

In the above example it is adding the ranks together(which makes sense), so I am getting [0,2,1,3]. Which isn't what I am looking for. I am trying to get 8 ranks so I can see individual ranks.

Expected result should be something like [2,1,5,7,4,0,6,3] which is the ranks when putting the two arrays side by side. Basically what I want is an absolute rank not a rank per array. So I only want one 1 unless the two values are the same. I don't want two arrays from 0-3, I want one from 0-7.

Ben.T
  • 29,160
  • 6
  • 32
  • 54
greenbur
  • 35
  • 8
  • Alright, I just added the expected output. Not sure if it makes the most sense but basically what I want is an absolute rank not a rank per array. So I only want one 1 unless the two values are the same. I don't want two arrays from 0-3, I want one from 0-7. – greenbur Jun 27 '19 at 17:29

1 Answers1

0

You need to concatenate the two arrays CI_SUM_1 and CI_SUM_2 before using argsort such as:

print (np.concatenate([CI_SUM_1,CI_SUM_2]).argsort().argsort())
array([2, 1, 5, 7, 4, 0, 6, 3], dtype=int64)
Ben.T
  • 29,160
  • 6
  • 32
  • 54
  • 1
    I actually just did that but with a different order and am getting a slightly different answer. What I did was make a variable 'z' which did the concatenate the did two argsorts with different lines and had it print which gave me [5,1,0,7,4,2,6,3]. So the 2,5 and 0 are different. Any idea why? `z = np.concatenate((CI_SUM_1,CI_SUM_2)) order1 = z.argsort – greenbur Jun 27 '19 at 17:48
  • Never mind, I was printing order rather than rank. Thank you for the help! I upvoted but don't have the reputation for it to show haha. – greenbur Jun 27 '19 at 17:55
  • @greenbur I see, you were pretty close with what you tried :) thanks for the ghost upvote haha – Ben.T Jun 27 '19 at 18:02