Open bersbersbers opened 1 month ago
There's some work in progress for this idea at https://github.com/Quansight-Labs/ndindex/issues/86. It needs some cleanup, but I think it should be doable and is definitely in scope.
I also agree that there should be a way to print indices in a way that uses direct Python syntax like 2:3
instead of Slice(2, 3)
.
ndindex
looks super useful. What I love is the way to abstract from the actual index type, thus being able to use integer- and slice-based indexing using the same data type. I had previously struggled in my code to convert integersi
toclice(i, i+1)
, but that was quite confusing when printing that representation back to the user...Speaking of the user, I have an app where they enter indices in text, and I convert their input into a slice (or Slice/Integer, soon) and use it for some computation. It would be super useful to have a function that converts strings such as
5
or:5:3
intondindex
objects, and also to printndindex
objects back into such canonical string representation.Given an array
a
and user inputs
as above, I would expectif that makes sense.
Also,
str(ndindex[s])
(orndindex[s].foo()
) should return pretty much its input, except for canonicalization.