You can use reduce(np.maximum, matrix) , here is the test:
import numpy as np np.random.seed(0) N, M = 1000, 1000 matrix = [np.random.rand(N) for _ in xrange(M)] %timeit np.max(matrix, axis = 0) %timeit np.max(np.vstack(matrix), axis = 0) %timeit reduce(np.maximum, matrix)
Result:
10 loops, best of 3: 116 ms per loop 10 loops, best of 3: 10.6 ms per loop 100 loops, best of 3: 3.66 ms per loop
Edit
`argmax () 'is harder, but you can use a for loop:
def argmax_list(matrix): m = matrix[0].copy() idx = np.zeros(len(m), dtype=np.int) for i, a in enumerate(matrix[1:], 1): mask = m < a m[mask] = a[mask] idx[mask] = i return idx
It is still faster than argmax() :
%timeit np.argmax(matrix, axis=0) %timeit np.argmax(np.vstack(matrix), axis=0) %timeit argmax_list(matrix)
result:
10 loops, best of 3: 131 ms per loop 10 loops, best of 3: 21 ms per loop 100 loops, best of 3: 13.1 ms per loop
source share