torch.Tensor.stride Tensor.stride(dim) → 元组或整数 返回self张量的步长。 Stride 表示在指定维度 dim 中从一个元素跳到下一个元素的距离。如果不传入参数,则返回所有 strides 的元组;否则,返回特定维度 dim 中的整数值作为 stride。 参数 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