Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:03:40+00:00 2026-05-28T03:03:40+00:00

I have a numpy.ndarray in which the maximum value will mostly occur more than

  • 0

I have a numpy.ndarray in which the maximum value will mostly occur more than once.

EDIT: This is subtly different from numpy.argmax: how to get the index corresponding to the *last* occurrence, in case of multiple occurrences of the maximum values because the author says

Or, even better, is it possible to get a list of indices of all the occurrences of the maximum value in the array?

whereas in my case getting such a list may prove very expensive

Is it possible to find the index of the last occurrence of the maximum value by using something like numpy.argmax? I want to find only the index of the last occurrence, not an array of all occurrences (since several hundreds may be there)

For example this will return the index of the first occurrence ie 2

import numpy as np
a=np.array([0,0,4,4,4,4,2,2,2,2])
print np.argmax(a)

However I want it to output 5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:03:41+00:00Added an answer on May 28, 2026 at 3:03 am

    numpy.argmax only returns the index of the first occurrence. You could apply argmax to a reversed view of the array:

    import numpy as np
    a = np.array([0,0,4,4,4,4,2,2,2,2])
    b = a[::-1]
    i = len(b) - np.argmax(b) - 1
    i     # 5
    a[i:] # array([4, 2, 2, 2, 2])
    

    Note numpy doesn’t copy the array but instead creates a view of the original with a stride that accesses it in reverse order.

    id(a) == id(b.base) # True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have numpy ndarray which contains two columns: one is date, e.g. 2011-08-04, another
I have a numpy.ndarray like this: array([[ 11.18033989, 0. ], [ 8.24621125, 3. ],
I have an object of type 'numpy.ndarray', called myarray, that when printed to the
This is a simplification of my question. I have a numpy array: x =
I will have to implement a convolution of two functions in Python, but SciPy/Numpy
I have a list containing objects of type numpy.ndarray, all list elements has same
Similar to this answer , I have a pair of 3D numpy arrays, a
I have a numpy array of ints representing time periods, which I'm currently plotting
I have a numpy array of strings. When a value in the array is
I have this numpy array: a = np.array([[[1,2,3],[-1,-2,-3]],[[4,5,6],[-4,-5,-6]]]) b is a transpose of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.