April 20, 2024, 12:07 p.m. | Super Kai (Kazuya Ito)

DEV Community dev.to

flatten() can remove zero or more dimensions from a 0D or more D tensor as shown below:


*Memos:




  • flatten() can be called both from torch and a tensor.

  • The 2nd argument(int) with torch or the 1st argument(int) with a tensor is start_dim which is the 1st dimension.

  • The 3rd argument(int) with torch or the 2nd argument(int) with a tensor is end_dim which is the last dimension.


  • flatten() can make a 0D tensor a 1D tensor.

  • Zero or more integers, floating-point …

dimensions flatten function memos pytorch tensor torch unflatten

AI Research Scientist

@ Vara | Berlin, Germany and Remote

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

Senior Machine Learning Engineer

@ Samsara | Canada - Remote