NumPy TutorialLesson 6Free preview
NumPy Array Slicing
This lesson is part of NumPy · All levels
Summary
Slicing allows you to take array snippets with syntax, similar to Python slicing lists but per dimension. In a 2D array, you can cut rows and columns at the same time like a[0:2, 1:4]. The negative step value reverses the order of the elements, so it's useful for quickly reversing the array.
Key points
- Slicing uses the [start:stop:step] syntax and is stop-exclusive.
- For 2D arrays, slicing is applied to each dimension separated by a comma.
- The negative step reverses the direction of the element's alignment.
- The result of slicing is generally a view, not a full copy.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.