pyodide/benchmark/benchmarks/create_grid.py

15 lines
406 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# http://stackoverflow.com/questions/13815719/creating-grid-with-numpy-performance
# pythran export create_grid(float [])
# setup: import numpy as np ; N = 800 ; x = np.arange(0,1,1./N)
# run: create_grid(x)
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 create_grid(x):
N = x.shape[0]
z = np.zeros((N, N, 3))
2018-10-03 18:59:01 +00:00
z[:, :, 0] = x.reshape(-1, 1)
z[:, :, 1] = x
fast_grid = z.reshape(N * N, 3)
2018-04-05 22:07:33 +00:00
return fast_grid