This is easily done in, for example, Python, and can be very useful. I have spent quite a bit of time searching documentation and reading forum questions, without finding anything.
Here’s a small example of what I would like to do:
arr = [1,2,3,4,-5]
sqmax = max(arr, by = x -> x^2)
I know this can be done as follows, but it seems like it would make sense for max() to have a by option.
That allocates an intermediate array for the squared array whereas the version from simon does not. It would be nice if we could reduce over a broadcasted array without allocs one day but we’re not there yet.
thanks for the answer, but maximum(f, arr) will return the maximal element in f(arr) rather than in arr.
Is there any keyword of maximum or other functons to “find x in arr s.t. f(x) is maximal”