w3resource

Numpy Array manipulation: fliplr() function

numpy.fliplr() function

The fliplr() function is used to flip array in the left/right direction.
Flip the entries in each row in the left/right direction. Columns are preserved, but appear in a different order than before.

Syntax:

numpy.fliplr(m)
NumPy manipulation: fliplr() function

Version: 1.15.0

Parameter:

Name Description Required /
Optional
m Input array, must be at least 2-D. Required

Return value:

ndarray - A view of m with the columns reversed. Since a view is returned, this operation is \mathcal O(1).

Example-1: numpy.fliplr()

>>> import numpy as np
>>> X = np.diag([1.,2.,3.,4.])
>>> X
array([[ 1.,  0.,  0.,  0.],
       [ 0.,  2.,  0.,  0.],
       [ 0.,  0.,  3.,  0.],
       [ 0.,  0.,  0.,  4.]])

Pictorial Presentation:

NumPy manipulation: fliplr() function

Example-2: numpy.fliplr()

>>> import numpy as np
>>> X = np.diag([1.,2.,3.,4.])
>>> np.fliplr(X)
array([[ 0.,  0.,  0.,  1.],
       [ 0.,  0.,  2.,  0.],
       [ 0.,  3.,  0.,  0.],
       [ 4.,  0.,  0.,  0.]])

Pictorial Presentation:

NumPy manipulation: fliplr() function

Example-3: numpy.fliplr()

>>> import numpy as np	   
>>> X = np.random.randn(3,5,7)

>>> np.all(np.fliplr(X) == X[:,::-1,...])
True

Python - NumPy Code Editor:

Previous: Rearrangeing elements flip()
Next: flipud()