这是一个简单的程序,其中我们必须反转一个numpy数组。我们将使用相同的功能。numpy.flip()
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.
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)输出结果Original Array: [10 20 30 40 50] Reversed Array: [50 40 30 20 10]