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.nn.Flatten.rst 1.0 kB

123456789101112131415161718192021222324252627282930313233343536
  1. mindspore.nn.Flatten
  2. ====================
  3. .. py:class:: mindspore.nn.Flatten
  4. 对输入Tensor的第0维的batch size之外的维度进行展平操作。
  5. **输入:**
  6. - **x** (Tensor) - 要展平的输入Tensor。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。数据类型为Number。
  7. **输出:**
  8. Tensor,shape为 :math:`(N,X)`,其中 :math:`X` 是输入 `x` 的shape除N之外的其余维度的乘积。
  9. **异常:**
  10. **TypeError** - `x` 不是Tensor。
  11. **支持平台:**
  12. ``Ascend`` ``GPU`` ``CPU``
  13. **样例:**
  14. >>> x = Tensor(np.array([[[1.2, 1.2], [2.1, 2.1]], [[2.2, 2.2], [3.2, 3.2]]]), mindspore.float32)
  15. >>> net = nn.Flatten()
  16. >>> output = net(x)
  17. >>> print(output)
  18. [[1.2 1.2 2.1 2.1]
  19. [2.2 2.2 3.2 3.2]]
  20. >>> print(f"Before flatten the x shape is {x.shape}.")
  21. 展平前x的shape为(2, 2, 2)
  22. >>> print(f"After flatten the output shape is {output.shape}.")
  23. 展平后输出的shape为(2, 4)