Skip to content

Meaning of negative index in System.Numerics.Tensors  #35075

@abgoswam

Description

@abgoswam

I am curious whats a negative index in System.Numerics.Tensors represents ?

            var arrayA = new[, ,]
            {
                {
                    {0, 1, 2},
                    {3, 4, 5}
                },
                {
                    {6, 7 ,8 },
                    {9, 10 ,11 },
                },
                {
                    {12, 13 ,14 },
                    {15, 16 ,17 },
                },
                {
                    {18, 19 ,20 },
                    {21, 22 ,23 },
                }
            };

            var tensorA = arrayA.ToTensor<int>(); // tensorA shape (4, 2, 3)
            var y = tensorA[2, -1, -2]; // **7**
            var z = tensorA[0, -1, -2]; // **throws error**

I was trying to draw parallels with numpy. Numpy results made sense.

a = np.array([ [[0,1,2], [3,4,5]],  [[6,7,8], [9,10,11]],  [[12,13,14],[15,16,17]]])
y = a[2,-1,-2]  # 16,  looks ok
z = a[0,-1,-2]  # 4, looks ok

@eerhardt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions