How to get indices of n maximum values in a numpy array?



How to get indices of n maximum values in a numpy array?..

Answer / Alka Rani

To get the indices of n maximum values in a NumPy array, you can use the 'argsort' method. Here is an example: arr = np.array([1, 5, -3, 6, 2]); indices = np.argpartition(arr, n=n)[:n]; max_values = arr[indices]

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Is there a null in python?

1 Answers  


What is zip() function in python?

1 Answers  


What does all do in python?

1 Answers  


What are the immutable build-in data types of python?

1 Answers  


How do I run python?

1 Answers  


What is the difference between uuid and guid?

1 Answers  


Explain split(), sub(), sub() methods of “re” module in python?

1 Answers  


Which compiler is best for python?

1 Answers  


How to use the slicing operator in Python?

3 Answers  


What does == mean?

1 Answers  


What is range() in python?

1 Answers  


Can I make games with python?

1 Answers  


Categories