Description
For example:
Asubset = A.sel[[1, 3, 5], :].new()
Asubset
is the same shape as A
, but only has values in rows 1, 3, and 5. The recipe for this example could be:
v = Vector.from_values([1, 3, 5], True, size=A.nrows)
Asubset = binary.second(v & A).new()
or
Asubset = Matrix(A.dtype, A.nrows, A.ncols)
Asubset[[1, 3, 5], :] = A[[1, 3, 5], :].new()
It's worth noting that binary.second(v & A)
is also a recipe (one that I find quite useful!). I actually don't know which recipe is better or whether one recipe dominates the other.
I've actually encountered this operation many times, and I often find myself unsure about how I should do it, hence this proposal to have nicer syntax that lets us--not the user--decide how to do it.
This is of course low priority and non-essential. There are also questions to consider:
- Can this be used to assign where the object on the right is the same size as the object on the left?
- Can masks be used?
I don't recall ever needing assignment, so I would skip assignment for now and only do extract. Masking when extracting seems natural and can be done efficiently.
Do we like A.sel[...]
, or are there better ways to spell this?
I'm fine letting this issue sit for a while. There are other fancy indexing people may want to do, such as:
- index using the structure or values of a vector,
A[v, :]
- what is the output shape? Same as
A
? Usingv.nvals
feels weird.
- what is the output shape? Same as
- index using vector masks,
A[v.S, w.V]
- what is the output shape? Same as
A
? - could we mix styles, such as
A[v.S, [1, 2, 3]]
?
- what is the output shape? Same as
- index using tuples, such as
A[((1, 5), (2, 10), (3, 15))]
orA.points[(1, 5), (2, 10), (3, 15)]
- this return a length 3 vector with elements from (1, 5), (2, 10), (3, 15)
- or maybe this would be
A.points[[1, 2, 3], [5, 10, 15]]
for faster recipe and possible adoption in C
We can discuss other indexing possibilities in this issue, but if anybody has a need for one of these, please open another issue to request it.