SoFunction
Updated on 2025-03-03

A brief analysis of the understanding of functions

() Function understanding

(input, dim)  When used, it is equivalent to  (dim)

() function plays a role in dimensionality upscaling. Dim equals to represent one in which dimension is added. For example, the original size=([4]) of x, after (0), it becomes size=([1, 4]), and after (1) becomes size=([4, 1]), note that dim∈[-() - 1, () + 1]
For example

Enter a one-dimensional tensor, i.e. ()=1

# Enter:x = ([1, 2, 3, 4])  # ()=1
print(x)
print()
y = (0)
print(y)
print()  # At this time ()=2z = (1)
print(z)
print()  # at this time()=2
#Output:tensor([1, 2, 3, 4])
([4])
tensor([[1, 2, 3, 4]])
([1, 4])
tensor([[1],
        [2],
        [3],
        [4]])
([4, 1])

Enter a two-dimensional tensor, i.e. ()=2

# Enter:x = ([[1, 2, 3], [4, 5, 6]])  # ()=2
print(x)
print()
y = (0)
print(y)
print()  # At this time ()=3z = (1)
print(z)
print()  # at this time()=3
#Output:tensor([[1, 2, 3],
        [4, 5, 6]])
([2, 3])
tensor([[[1, 2, 3],
         [4, 5, 6]]])
([1, 2, 3])
tensor([[[1, 2, 3]],
        [[4, 5, 6]]])
([2, 1, 3])

Enter a four-dimensional tensor, i.e. ()=4

# Enter:x = ([[[[1, 2, 3], 
                    [4, 5, 6]],
                [[0, 2, 1], 
                 [1, 5, 2]]],
                [[[1, 2, 3], 
                  [4, 5, 6]],
                [[0, 2, 1], 
                 [1, 5, 2]]]])
print(x)
print()
y2 = (2)
print(y2)
print()
y3 = (3)
print(y3)
print()
#Output:tensor([[[[1, 2, 3],
          [4, 5, 6]],
         [[0, 2, 1],
          [1, 5, 2]]],
        [[[1, 2, 3],
          [4, 5, 6]],
         [[0, 2, 1],
          [1, 5, 2]]]])
([2, 2, 2, 3])
tensor([[[[[1, 2, 3],
           [4, 5, 6]]],
         [[[0, 2, 1],
           [1, 5, 2]]]],
        [[[[1, 2, 3],
           [4, 5, 6]]],
         [[[0, 2, 1],
           [1, 5, 2]]]]])
([2, 2, 1, 2, 3])
tensor([[[[[1, 2, 3]],
          [[4, 5, 6]]],
         [[[0, 2, 1]],
          [[1, 5, 2]]]],
        [[[[1, 2, 3]],
          [[4, 5, 6]]],
         [[[0, 2, 1]],
          [[1, 5, 2]]]]])
([2, 2, 2, 1, 3])

This is all about this article about the understanding of () function. For more related () function content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!