mindspore.Tensor.contiguous
- mindspore.Tensor.contiguous()[源代码]
将Tensor转成一个连续内存的Tensor,该Tensor包含与原Tensor相同的数据。
- 返回:
一个连续内存的Tensor,该Tensor包含与原Tensor相同的数据。
样例:
>>> import mindspore as ms >>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor([[1, 2, 3], [4, 5, 6]], dtype=ms.float32) >>> y = ops.transpose(x, (1, 0)) >>> y.contiguous() >>> y[:, 1] = 1 >>> print(x) [[1. 2. 3.] [4. 5. 6.]]