torch.Tensor.stride¶ Tensor.stride(dim) → tuple 或 int¶ 返回 self 張量的步長。 步長是移動到指定維度 dim 中下一個元素所需的步進量。未傳入引數時,返回所有維度的步長組成的 tuple。否則,返回指定維度 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