torch.Tensor.stride¶ Tensor.stride(dim) → tuple or int¶ 返回 self 张量的步幅。 Stride 是跳转到指定维度 dim 中下一个元素所需的跳跃。当没有传递参数时,返回所有步长的元组。否则,返回特定维度 dim 中的步长作为整数值。 Parameters 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