Numpy v 1.9 contains two seemingly identical functions: 'flatten' and 'ravel'
What is the difference? and when might I pick one vs the other for converting a 2-D np.array to 1-D?
Numpy v 1.9 contains two seemingly identical functions: 'flatten' and 'ravel'
What is the difference? and when might I pick one vs the other for converting a 2-D np.array to 1-D?
Aha:
The primary functional difference is thatflatten
is a method of an ndarray object and hence can only be called for true numpy arrays. In contrast ravel()
is a library-level function and hence can be called on any object that can successfully be parsed. For example ravel()
will work on a list of ndarrays, while flatten (obviously) won't.
In addition, as @jonrsharpe pointed out in his comment, the flatten method always returns a copy, while ravel only does so "if needed." Still not quite sure how this determination is made.