Slicing and Indexing in numpyArrays

Slicing refers to extracting a range of elements from the array. The format of slicing operation is given here:


The default value for ?start’ is 0, for ?stop’ is n-1 (n is number of elements) and for ?stepsize’ is 1. Counting starts from 0th position. For example, if we write:

a = [10, 11, 12, 13, 14, 15]


example image for array slicing example image for array sliceindex

Suppose, we write a[:] or a[::] without specifying anything for start, stop and stepsize, it will extract from 0th element till the end of the array. So, all elements are extracted. Suppose, we write a[2:], it starts at 2nd element and ends at last element.

What will be the output of the following program

Python program to understand slicing operations on arrays.

Python program to retrieve and display elements of a numpy array using indexing.