[Numpy-discussion] Create a n-D grid; meshgrid alternative
stefan.otte at gmail.com
Sun May 10 07:40:52 EDT 2015
quite often I want to evaluate a function on a grid in a n-D space.
What I end up doing (and what I really dislike) looks something like this:
x = np.linspace(0, 5, 20)
M1, M2 = np.meshgrid(x, x)
X = np.column_stack([M1.flatten(), M2.flatten()])
X.shape # (400, 2)
I don't think I ever used `meshgrid` in any other way.
Is there a better way to create such a grid space?
I wrote myself a little helper function:
for space in np.meshgrid(*linspaces)])
But maybe something like this should be part of numpy?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion