pyodide/benchmark/benchmarks/multiple_sum.py

19 lines
437 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# from http://stackoverflow.com/questions/77999777799977/numpy-vs-cython-speed
# pythran export multiple_sum(float[][])
# setup: import numpy as np ; r = np.random.rand(100,100)
# run: multiple_sum(r)
2018-04-05 22:07:33 +00:00
import numpy as np
2018-10-03 12:38:48 +00:00
2018-04-05 22:07:33 +00:00
def multiple_sum(array):
rows = array.shape[0]
cols = array.shape[1]
out = np.zeros((rows, cols))
for row in range(0, rows):
out[row, :] = np.sum(array - array[row, :], 0)
return out