mindspore.Tensor.contiguous

View Source On Gitee
Tensor.contiguous()[source]

Converts a Tensor into a continuous-memory Tensor that contains the same data as the original Tensor.

Returns

A contiguous in memory tensor containing the same data as self tensor.

Examples

>>> 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.]]