mindspore.Tensor.init_data

Tensor.init_data(slice_index=None, shape=None, opt_shard_group=None)[source]

Get the tensor format data of this Tensor.

Note

The init_data function can be called once for the same tensor.

Parameters
  • slice_index (int) – Slice index of a parameter's slices. It is used when initialize a slice of a parameter, it guarantees that devices using the same slice can generate the same tensor. Default: None.

  • shape (list[int]) – Shape of the slice, it is used when initialize a slice of the parameter. Default: None.

  • opt_shard_group (str) – Optimizer shard group which is used in auto or semi auto parallel mode to get one shard of a parameter's slice. For more information about optimizer parallel, please refer to: Optimizer Parallel. Default: None.

Returns

Initialized Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> from mindspore.common.initializer import initializer, Constant
>>> x = initializer(Constant(1), [2, 2], ms.float32)
>>> out = x.init_data()
>>> print(out)
[[1. 1.]
 [1. 1.]]