• notice
  • Congratulations on the launch of the Sought Tech site

Python program to invert a Numpy array?

Here is a simple program in which we have to reverse a numpy array. We will use the same function. numpy.flip()

algorithm


Step 1: Import numpy.
Step 2 : Define a numpy array using numpy.array ( ).
Step 3 : Reverse the array using numpy.flip() function.
Step 4: Print the array.


sample code


import numpy as np

arr = np.array([ 10 , 20 , 30 , 40 , 50 ])
print( "Original Array: \n" , arr)

arr_reversed = np.flip(arr)
print( "\nReversed Array: \ n" , arr_reversed)

output result

Original Array:
[10 20 30 40 50 ]

Reversed Array:
[50 40 30 20 10 ]


Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+