Jun-12-2018, 02:20 AM
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:
I want to get this:
I have tried the following:
and it's obv giving me the wrong answer! Any ideas how to fix this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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 ])] |
1 2 3 4 |
[ 126 23 ; 129 125 ; 132 41 ; 142 76 ] |
1 2 3 4 |
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) |