Hello geeks and welcome in this article, we will cover NumPy fliplr. Along with that, we will also look at its syntax and parameters. To make the topic crystal clear, we will also look at a couple of examples. But at first, let us try to understand NumPy.fliplr() through its definition. Suppose you have a matrix with you. A demand arrives where you need to flip the entries in each row with the column being preserved. This function will come in handy in this situation, and you can achieve it with just a single line of code. Now moving ahead, we will look at its syntax, followed by parameters.

Contents of Tutorial

## SYNTAX OF NUMPY FLIPLR()

Given below is the general syntax for this function

`numpy.fliplr`

(m)

A relatively simple syntax when compared to other functions of NumPy. It has only one parameter associated with it that we will be discussing next.

## PARAMETERS OF NUMPY FLIPLR()

**M: array_like**

It represents the input array over which the operation needs to be performed. The input array must be at least 2-dimensional for this function to work. For a 1-d array, you can use another function called numpy. flipud().

## RETURN

**f:ndarray**

It returns an output array with the columns reversed . Since the operation is returned the operation is O(1).

Now with the syntax and parameters being done. Let us look at couple of examples that help us in understanding the concept better.

## EXAMPLES

#input import numpy as ppool a=[[1,23], [34,6]] print(ppool.fliplr(a))

**Output:**

```
[[23 1]
[ 6 34]]
```

Above, we can see the straightforward example of NumPy fliplr. In the above example, we have first imported the NumPy module. Following this, we have defined a 2-dimensional array. In the last line of our code, we have used the print statement. Our output justifies our input and our function. We get [23,1] which reverse of [1,23] and [6,34] reverse of [34,6]. Here we can see the same row elements are flipped while the shape of the array is preserved.

Now let us look another example with a 3-dimensional matrix.

#input import numpy as ppool a=[[1,2,3], [4,5,6], [7,8,9]] print(ppool.fliplr(a))

**Output:**

```
[[3 2 1]
[6 5 4]
[9 8 7]]
```

In the above example, the only difference is that we have used a 3-d array. We have first imported the NumPy module. Following which we have defined our array and then used a print statement to get our desired output. Here we can see that again, and the values are switched from left to right. At the same time, the shape of the array is still maintained. Here we can see the position of the middle element remains unchanged.

## NUMPY.FLIPLR() VS FLIPUD()

In this section, we will be comparing two of the NumPy function and the basic differences between them. As stated above we know that the fliplr() function is used to flip the array from left to the right direction. On contrary, the flipud() function is used to shift the function from up to down.

Now let us look at the effect of the function on a similar array.

fliplr() | flipud() |

import numpy as ppool a=[[1,2], [3,4]] print(ppool.fliplr(a)) | import numpy as ppool a=[[1,2], [3,4]] print(ppool.flipud(a)) |

#ouptut [[2 1] [4 3]] | #ouput [[3 4] [1 2]] |

From the above table we can draw conclusion. Also we can spot the basic difference between the 2 function.

## MUST READ

## CONCLUSION

In this article, we covered NumPy fliplr. Along with that, we looked at its syntax and parameters. For a better understanding, we looked at a couple of examples. In the end, we can conclude that NumPy.fliplr() is used to shift the array left to right with preserving the shape of the array. I hope this article can clear all of your doubts and make this topic crystal clear to you. If you still have any unsolved queries or doubts, feel free to write them below in the comment section. Done reading this, why not read NumPy vstack next.

Comments are closed.