Skip to content
Advertisement

What is the difference between .flatten() and .view(-1) in PyTorch?

Both .flatten() and .view(-1) flatten a tensor in PyTorch. What’s the difference?

  1. Does .flatten() copy the data of the tensor?
  2. Is .view(-1) faster?
  3. Is there any situation that .flatten() doesn’t work?

Advertisement

Answer

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement