I created an issue regarding
end keyword in creating
CartesianIndex in Julia repository a while ago (https://github.com/JuliaLang/julia/issues/33608):
It is not possible to create a
CartesianIndex object using
This following code does not work in Julia:
In Python, this is possible using
import numpy arr= numpy.array([[4, 2, 3], [2, 5, 4]]) ind=(-1,1) # similar to CartesianIndex arr[ind]
This is useful for creating algorithms that are independent of the array, such as for
sortperm(A, dim) issue open since 2016
And I got a response from @Keno that:
You can definitely create a type that behaves like this, it just doesn’t have the same semantics as
endwhich is defined to looks for the innermost enclosing array (so it does do what you want if you construct the Cartesian index inside the array access). Closing, since this conflicts with
ends semantics, but I would encourage you to try writing the type that behaves like this yourself. It shouldn’t be more than 15 lines of code. If you need help, feel free to open a thread on discourse.
How can I do this?