4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by vegaseat
0

Can you show what you mean by 2d array as there are many alternatives. Looks from tags that you are using numpy. I am not very familiar with it. I know general way of ziping items together with their indexes and sorting the tuples, but numpy should have optimized functions for this.

Edited by pyTony: n/a

0

You have to iterate through the entire array, whether you write you own or use a built in method. Since you also want the max also, go through the array once, storing any number that is larger than the current maximum, along with it's position.

Edited by woooee: n/a

0

Just a few common Python functions will do ...

# find the index of the largest item in a list
# index starts at zero

a = [77, 123, 18]

a_max = max(a)
ix_max = a.index(a_max)

print(a)       # [77, 123, 18]
print(a_max)   # 123
print(ix_max)  # 1
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.