Numpy.fliplr() Method: How to use Numpy.fliplr() Function in Python

Numpy fliplr() function is used to flip the array in the left-right direction. The shape of the array is preserved. The fliplr() function is used to flip array in the left/right direction. Python NumPy.fliplr() function flips the entries in each row in the left/right direction. The columns are preserved but appear in a different order than before.

Numpy fliplr()

The NumPy.fliplr(array) function flips the array(entries in each column) in left-right direction. The shape of an array is preserved.

Syntax

``numpy.fliplr(array)``

Parameters

The fliplr() function takes an array as a parameter.

Return Value

The fliplr() function returns the array the same array as flipped in the left-right direction.

Numpy.fliplr() Method with Example

Example 1: How to Use the numpy.fliplr() Method

``````import numpy as np

arr = np.arange(4).reshape((2, 2))
print("Original array : \n", arr)
print("\nFlipped array left-right : \n", np.fliplr(arr))``````

Output

``````Original array :
[[0 1]
[2 3]]

Flipped array left-right :
[[1 0]
[3 2]]``````

Example 2: Reshaping array left-right

``````import numpy as np

arr = np.arange(9).reshape((3, 3))
print("Original array : \n", arr)
print("\nFlipped array left-right : \n", np.fliplr(arr))``````

Output

``````Original array :
[[0 1 2]
[3 4 5]
[6 7 8]]

Flipped array left-right :
[[2 1 0]
[5 4 3]
[8 7 6]]``````