You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.ops.OnesLike.rst.txt 905 B

123456789101112131415161718192021222324252627282930313233343536
  1. mindspore.ops.OnesLike
  2. ======================
  3. .. py:class:: mindspore.ops.OnesLike(*args, **kwargs)
  4. 创建新Tensor。所有元素的值都为1。
  5. 返回填充了Scalar值为1的具有与输入相同shape和数据类型的Tensor。
  6. **输入:**
  7. **input_x** (Tensor) - 输入Tensor。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。
  8. **输出:**
  9. Tensor,具有与 `input_x` 相同的shape和类型,并填充了1。
  10. **异常:**
  11. **TypeError:** `input_x` 不是Tensor。
  12. **支持平台:**
  13. ``Ascend`` ``GPU`` ``CPU``
  14. **样例:**
  15. .. code-block::
  16. >>> oneslike = ops.OnesLike()
  17. >>> input_x = Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))
  18. >>> output = oneslike(input_x)
  19. >>> print(output)
  20. [[1 1]
  21. [1 1]]