5 Ways To Flatten an Array in NumPy

How to process an n-dimensional array as if it was a vector

Lev Maximov
Better Programming
Published in
6 min readMay 29, 2023

--

All images by author

NumPy, a powerful Python library for scientific computing, has quite a few methods for an operation as simple as flattening, but there’s a good reason. Usually, you don’t need to worry too much about the difference: the recipe “flatten is always a copy, and reshape(-1) is a view whenever possible” from…

--

--