0

How can I determine the row with the highest value in index=0 even if index=1 is a character?

I have an array of lists with two positions, where the first position is a number and the second position is a character.

A=np.array([[150,"A"],[9,1],[9,14]])
B=np.argmax(A, axis=0)

I should receive this:

[0 2]  

But I get this:

[1 0]

I am not sure what the output for the seconde position is but for the first position it should be 0. What did I get wrong about the function? Even slicing did not work out.

Bryan McGill
  • 237
  • 1
  • 2
  • 8
  • DId you look at `A` before trying to do the `argmax`? What's the `dtype`? – hpaulj Mar 22 '19 at 17:29
  • Well, the type gets converted to characters, but I tried doing this: A=np.array([[150,"A"],[9,1],[9,14]], dtype='|i, i') Still doesn't help. – Bryan McGill Mar 22 '19 at 17:34
  • 1
    So it's giving you the right argmax for characters. If you want it to ignore the 'A` you have get rid of it even before make the array. You might want to rethink the task, because mixing characters and numbers in an array can give all kinds of problems, not just this. – hpaulj Mar 22 '19 at 17:35
  • I was hoping to stick those value pairs together, because it is not a numerical matrix what I am handling. It's more a value pair, where I can treat the first value as number. Anyways thanks for your help. – Bryan McGill Mar 22 '19 at 17:42

1 Answers1

0

I've found a solution. I do not know, if I will run into issues later on!

A=np.array([(150,"A"),(30,"B"),(9,"14")], dtype='object')
c=np.argmax(A, axis=0)
Bryan McGill
  • 237
  • 1
  • 2
  • 8