From the course: NumPy Essential Training: 1 Foundations of NumPy
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Reversing an array
From the course: NumPy Essential Training: 1 Foundations of NumPy
Reversing an array
- [Instructor] Let's learn how to the reverse the contents of an array along the axis. Before exploring how to use the flip function, let's learn another way to reverse a one dimensional array using slicing. We already learned the syntax for array slicing is Start, Stop, Step. Values for the Start and Stop field are optional, with default value set to 0 for Start and the string length for Stop. If it puts step-1, it indicates starting from the end and stopping at the start to get array reversed. Let's import numpy as np and create a one dimensional array of 10 integers and call it arr_1dim. We're going to reverse array by typing arr_1dim [||-1 ] Great, now let's see our flip function in action, flip function reverses the order of aray elements along specified axis, preserving the shape of the array. It's takes two parameters, input array and axis along which array is reversed. As a result, it returns a reversed array which shape preserved. For reversing the array arr_1dim, we will…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.