Yeah, no matter what you do that example will look ugly. :-)

I'm not sure what the (1, 1) and (1, 2) in your example stand for (I'm not familiar with your field), but it appears these index the 5th and 6th (base 0) dimension? It does sound like you're better off defining a custom function to make this notation more manageable. Maybe A.slice((1, 1, 1), (1, 2, 0))?

On Fri, Dec 11, 2020 at 8:57 PM Hao Zhang via Typing-sig <typing-sig@python.org> wrote:

Well, PEP 637 looks great.

I agree that this situation is too rare, so maybe single parameter is a better choice.

If you are interested, let me share a complicated example :-)

I have a class which contains something like a finite square lattice(such as a 4x4 lattice who owns 16 sites), and there is a huge-rank "tensor" to decsribe it, with one index for every sites, for 4x4 lattice, it is a 2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2 tensor(16-rank). With the same thought in the previous example, I use `tuple[int, int]` to specify the index of this big tensor to get item or to get something like "slice of tensor", look like:

```

result = A[{(1,1): 1, (1,2): 0}]

```

This is a sliced tensor which rank is 16-2=14, since two of 16 index in tensor A are fixed. Just like this in numpy

```

result = A[:, :, :, :, :, 1, 0, :, :, :, :, :, :, :, :, :]

```

Don't worry about complexity of this "tensor", I am no using dense tensor to store it, I am using a network(a tensor network) to approximate this huge-rank tensor, although I want to treat it more like a normal tensor.

PEP 637 cannot be used in this case, but maybe I should not use `__getitem__` here?

_______________________________________________

Typing-sig mailing list -- typing-sig@python.org

To unsubscribe send an email to typing-sig-leave@python.org

https://mail.python.org/mailman3/lists/typing-sig.python.org/

Member address: guido@python.org

--

--Guido van Rossum (python.org/~guido)