Skip to content
Advertisement

Elegant way to create a discrete coordinate system array in numpy

I want to define an array which contains all combinations of values

[0, 0], [0, 1], [0, 2], …, [0,N],

[1, 0], [1, 1], [1, 2], …, [1, N],

[N, 0], [N, 1], [N,2], …, [N,N].

Obviously, one could do something like this:

JavaScript

However, I find this “ugly”. Is there a clean way to generate such an array?

Advertisement

Answer

You can use np.indices, if you prefer:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement