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.

说明

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

参数
  • 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.

返回

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

异常

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

Supported Platforms:

Ascend GPU CPU

样例

>>> import mindspore.numpy as np
>>> a = np.ones((4,1,2))
>>> output = np.empty_like(a)
>>> print(output)
[[[0. 0.]]
 [[0. 0.]]
 [[0. 0.]]
 [[0. 0.]]]