Home > Mobile >  Reshaping Arrays In Python
Reshaping Arrays In Python

Time:01-04

Why flatten() is slower than ravel() function in reshaping arrays in python?

x = np.arange(1000000)
x.shape = 100, 100, 100
%timeit x.flatten() 
%timeit x.ravel()

NumPy offers many functions and some of them can produce same results I think it depends on being Inplace and not.

CodePudding user response:

flatten always makes a copy. ravel makes a view if it can. Copying takes time.

  • Related