torch.Tensor.stride¶
- Tensor.stride(dim) tuple or int ¶
傳回
self
tensor 的 stride。Stride(步幅)是指在指定的維度
dim
中,從一個元素移動到下一個元素所需的跳躍距離。如果沒有傳入引數,則會返回包含所有步幅的元組。否則,會返回一個整數值,表示特定維度dim
的步幅。- 參數
dim (int, 可選) – 所需步幅的目標維度
範例
>>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) >>> x.stride() (5, 1) >>> x.stride(0) 5 >>> x.stride(-1) 1