mindspore.numpy.empty_like

mindspore.numpy.empty_like(prototype, dtype=None, shape=None)[源代码]

Returns a new array with the same shape and type as a given array.

Note

Input array must have the same size across a dimension. If prototype is not a Tensor, dtype is float32 by default if not provided.

Parameters
  • prototype (Union[Tensor, list, tuple]) – The shape and data-type of prototype define these same attributes of the returned array.

  • dtype (mindspore.dtype, optional) – Overrides the data type of the result.

  • shape (int or sequence of ints, optional) – Overrides the shape of the result.

Returns

Tensor, array of uninitialized (arbitrary) data with the same shape and type as prototype.

Raises

ValueError – If prototype is not a Tensor, list or tuple.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> a = np.ones((4,1,2))
>>> output = np.empty_like(a)
>>> print(output)
Tensor(shape=[4, 1, 2], dtype=Float32, value=
<uninitialized>)