This article explains the NumPy array Slicing. Learn to slice an array of any dimension into another array having items of a given range with examples.

Table of Contents

NumPy Array Slicing

The content present in the NumPy arrays can be made accessible, and also we can make changes thorough indexing as we got to know in the previous module. Another way of data manipulation in arrays in NumPy is though slicing through the arrays. We can also try changing the position of the elements in the array with the help of their index number. Slicing is the extension of python’s basic concept of changing position in the arrays of N-d dimensions.

Slicing, in very simple words, means changing the position of elements from one given index to another given index.

We give the value of slice in this form [Start: End], and there is also another way in which we also define step attribute which could be written in this form [ Start:End:Step]

Some steps we need to keep in mind while giving these parameters:

  • If we do not give any value for start, then it is considered 0 by default.
  • If we do not give any value for the end, then it would consider the length of the array in the given dimension.
  • Also, if we do not give value for the step, then it is considered 1 by default.

#miscellaneous #arrays #indexing #multi-dimensional arrays #numpy #python #python tutorial

NumPy Array Slicing (Python Tutorial)
3.50 GEEK