I’d like to support a dynamic dimension. My current workaround is:
def tensor_slice(tensor, dim, s):
    if dim < 0:
        dim += tensor.dim()
    return tensor[(slice(None),) * dim + (s, )]

I do it to implement packbits: https://github.com/pytorch/pytorch/issues/32867 3
A question: if I do as_strided instead, can I control the shape of the result? Basically I need to select every 8th bool element, then every 8th+1, … 8th+7 in order to pack them into one uint8 array.