python - How to find which numpy array contains the maximum value on an element by element basis? -


given list of numpy arrays, each same dimensions, how can find array contains maximum value on element-by-element basis?

e.g.

import numpy np def find_index_where_max_occurs(my_list):     # d = ...  goes here ...     return d  a=np.array([1,1,3,1]) b=np.array([3,1,1,1]) c=np.array([1,3,1,1])  my_list=[a,b,c]  array_of_indices_where_max_occurs = find_index_where_max_occurs(my_list)  # want: # >>> print array_of_indices_where_max_occurs # array([1,2,0,0]) # i.e. first element, maximum value occurs in array b @ index 1 in my_list. 

any appreciated... thanks!

another option if want array:

>>> np.array((a, b, c)).argmax(axis=0) array([1, 2, 0, 0]) 

so:

def f(my_list):     return np.array(my_list).argmax(axis=0) 

this works multidimensional arrays, too.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -