Re: [Numpy-discussion] Create a n-D grid; meshgrid alternative
I'm totally in favor of the 'gridspace(linspaces)' version, as you probably end up wanting to create grids of other things than linspaces (e.g. a logspace grid, or a grid of random points etc.). It should be called somewhat different though. Maybe 'cartesian(arrays)'? Best, Johannes Quoting Stefan Otte (2015-05-10 16:05:02) I just drafted different versions of the `gridspace` function: https://tmp23.tmpnb.org/user/1waoqQ8PJBJ7/notebooks/2015-05%20gridspace.ipynb Beste Grüße, Stefan On Sun, May 10, 2015 at 1:40 PM, Stefan Otte stefan.o...@gmail.com wrote: Hey, 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) fancy_function(X) 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: def gridspace(linspaces): return np.column_stack([space.flatten() for space in np.meshgrid(*linspaces)]) But maybe something like this should be part of numpy? Best, Stefan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion -- Question: What is the weird attachment to all my emails? Answer: http://en.wikipedia.org/wiki/Digital_signature ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] tie breaking for max, min, argmax, argmin
Hello, I wonder if it would be worth to enhance max, min, argmax and argmin (more?) with a tie breaking parameter: If multiple entries have the same value the first value is returned by now. It would be useful to have a parameter to alter this behavior to an arbitrary tie-breaking. I would propose, that the tie-breaking function gets a list with all indices of the max/mins. Example: a = np.array([ 1, 2, 5, 5, 2, 1]) np.argmax(a, tie_breaking=random.choice) 3 np.argmax(a, tie_breaking=random.choice) 2 np.argmax(a, tie_breaking=random.choice) 2 np.argmax(a, tie_breaking=random.choice) 2 np.argmax(a, tie_breaking=random.choice) 3 Especially for some randomized experiments it is necessary that not always the first maximum is returned, but a random optimum. Thus I end up writing these things over and over again. I understand, that max and min are crucial functions, which shouldn't be slowed down by the proposed changes. Adding new functions instead of altering the existing ones would be a good option. Are there any concerns against me implementing these things and sending a pull request? Should such a function better be included in scipy for example? Best, Johannes ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion