torch.Tensor.stride¶ Tensor.stride(dim) → tuple 或 int¶ 返回 self 张量的步幅。 步幅是指在指定维度 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