Python Forum
Get max values based on unique values in another list - python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get max values based on unique values in another list - python
#1
In a numpy.ndarray (2d) I want to calculate the maximum of corresponding values (second column) of repetitive values (first column) in the array. Like if the array is this:

sys_func = 

array([[126.        ,   4],
           [126.        ,  11],
           [126.        ,   2],
           [126.        ,  12],
           [126.        ,  23],
           [126.        ,   1],
           [129.        ,  11],
           [129.        ,  45],
           [129.        ,   3],
           [129.        , 125],
           [129.        ,  54],
           [129.        ,   1],
           [129.        ,   1],
           [129.        ,  53],
           [132.        ,  41],
           [132.        ,   1],
           [132.        ,   2],
           [142.        ,   6],
           [142.        ,  76        ]])

unique_days = [int(x) for x in np.unique(sys_func[:,0])]
I want to get this:

[126 23;
129 125;
132 41;
142 76]
I have tried the following:

max_sr = []
for i in range(len(unique_days)):
    s = [max(sys_func[:,1]) for x in np.where(sys_func[:,0] == unique_days[i])]
    max_sr.append(s)
and it's obv giving me the wrong answer! Any ideas how to fix this?
Reply


Messages In This Thread
Get max values based on unique values in another list - python - by Antonio - Jun-12-2018, 02:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Assigning conditional values in Pandas Scott 3 863 Dec-19-2023, 03:10 AM
Last Post: Larz60+
  attempt to split values from within a dataframe column mbrown009 8 2,428 Apr-10-2023, 02:06 AM
Last Post: mbrown009
  Make unique id in vectorized way based on text data column with similarity scoring ill8 0 912 Dec-12-2022, 03:22 AM
Last Post: ill8
  Increase df column values decimals SriRajesh 2 1,132 Nov-14-2022, 05:20 PM
Last Post: deanhystad
  replace sets of values in an array without using loops paul18fr 7 1,791 Jun-20-2022, 08:15 PM
Last Post: paul18fr
  Changing Values in a List DaveG 1 1,309 Apr-04-2022, 03:38 PM
Last Post: jefsummers
Question How does one clean a populated table in MySQL/MariaDB? Copying values across tables? BrandonKastning 2 1,591 Jan-17-2022, 05:46 AM
Last Post: BrandonKastning
  Matplotlib scatter plot in loop with None values ivan_sc 1 2,299 Nov-04-2021, 11:25 PM
Last Post: jefsummers
  pandas: Compute the % of the unique values in a column JaneTan 1 1,804 Oct-25-2021, 07:55 PM
Last Post: jefsummers
  Write a dictionary with arrays as values into JSON format paul18fr 3 5,734 Oct-20-2021, 10:38 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020