torch.Tensor.set_#
- Tensor.set_(source=None, storage_offset=0, size=None, stride=None) Tensor #
设置底层的存储、大小和步幅。如果
source
是一个 tensor,那么self
tensor 将共享相同的存储,并具有与source
相同的尺寸和步幅。在一个 tensor 中对元素的更改将反映在另一个 tensor 中。如果
source
是一个Storage
,该方法将设置底层的存储、偏移量、尺寸和步幅。- 参数
source (Tensor 或 Storage) – 要使用的 tensor 或存储
storage_offset (int, optional) – 存储中的偏移量
size (torch.Size, optional) – 期望的尺寸。默认为源的尺寸。
stride (tuple, optional) – 期望的步幅。默认为 C 连续步幅。