본문 바로가기
python

check pytorch tensor size

by 타닥타닥 토다토닥 부부 2023. 8. 9.
반응형

check pytorch tensor size

 

import torch

## allocate sample tensor to x
x = torch.FloatTensor([
    [1, 2],
    [3, 4],
    [5, 6],
    [7, 8]
])

## size with "size" method
x.size()
# out : torch.Size([4, 2])

## size with "shape" method
x.shape
# out : torch.Size([4, 2])

## dimension with "dim" method
x.dim()
# out : 2

## size on 0 dimension with "size(0)" method
x.size(0)
# out : 4

x.shape[0]
# out: 4
반응형

댓글