What is the difference between flip() and flipud() in NumPy?
Both functions do the same things so which one should I use?
CodePudding user response:
Both functions do the same things
That's only true for 1-D arrays.
For N-D arrays, np.flipud(a) is only the same as np.flip(a, axis=0). There's another convenience function np.fliplr(a) that corresponds to np.flip(a, axis=1).
np.flip is required if you need to flip dimension 3 or higher, e.g., the 3rd dimension (axis 2):
np.flip(a, axis=2)
Or to flip multiple dimensions at once, e.g., the 1st and 3rd dimensions (axis 0 and 2):
np.flip(a, axis=(0, 2))
CodePudding user response:
flipud can only flip an array along the vertical axis and flip will flip along a given axis. Very similiar.
