Question
What could be the fastest way to build an array of sequence ordered list with numpy?
Say that we start with this situation:
blue numbers correspond to index of the position
This was generated by using this script:
# u v parameters allow to define how many points according to x and y
u, v = (3, 3)
x = np.linspace(0, 2, u)
y = np.linspace(0, 1, v)
# meshgrid used to create a grid out of several arrays
xx, yy, zz = np.meshgrid(x, y, 0)
# reshaping matrix
coords = np.dstack((xx,yy,zz))
coords = np.vstack(coords)
Considering that u and v can be different and very large numbers, the main objective would be to create an array of list following this scheme:
meaning something like :
[[0 1 4 3]
[1 2 5 4]
[3 4 7 6]
[4 5 8 7]]
@hpaulj here are some examples which shows the influence of u and v parameters
The solution I was able to find corresponds to this:
listing = np.array([((u)*j+i, (u)*j+i+1, (u)*j+i+u+1, (u)*j+i+u) for j in range(v-1) for i in range(u-1)])
Can anyone think of a better way (cleaner, faster, more array) to achieve the same result?