The syntax is:

a[start:stop]  # items start through stop-1
a[start:]      # items start through the rest of the array
a[:stop]       # items from the beginning through stop-1
a[:]           # a copy of the whole array

There is also the step value, which can be used with any of the above:

a[start:stop:step] # start through not past stop, by step

The key point to remember is that the :stop value represents the first value that is not in the selected slice. So, the difference between stop and start is the number of elements selected (if step is 1, the default).

The other feature is that start or stop may be a negative number, which means it counts from the end of the array instead of the beginning. So:

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items

Similarly, step may be a negative number:

a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed

Python is kind to the programmer if there are fewer items than you ask for. For example, if you ask for a[:-2] and a only contains one element, you get an empty list instead of an error. Sometimes you would prefer the error, so you have to be aware that this may happen.

Relationship with the slice object

A slice object can represent a slicing operation, i.e.:

a[start:stop:step]

is equivalent to:

a[slice(start, stop, step)]

Slice objects also behave slightly differently depending on the number of arguments, similar to range(), i.e. both slice(stop) and slice(start, stop[, step]) are supported. To skip specifying a given argument, one might use None, so that e.g. a[start:] is equivalent to a[slice(start, None)] or a[::-1] is equivalent to a[slice(None, None, -1)].

While the :-based notation is very helpful for simple slicing, the explicit use of slice() objects simplifies the programmatic generation of slicing.

Answer from Greg Hewgill on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_slicing.asp
NumPy Array Slicing
Slicing in python means taking elements from one given index to another given index. We pass slice instead of index like this: [start:end]. We can also define the step, like this: [start:end:step]. ... Note: The result includes the start index, ...
Top answer
1 of 13
6667

The syntax is:

a[start:stop]  # items start through stop-1
a[start:]      # items start through the rest of the array
a[:stop]       # items from the beginning through stop-1
a[:]           # a copy of the whole array

There is also the step value, which can be used with any of the above:

a[start:stop:step] # start through not past stop, by step

The key point to remember is that the :stop value represents the first value that is not in the selected slice. So, the difference between stop and start is the number of elements selected (if step is 1, the default).

The other feature is that start or stop may be a negative number, which means it counts from the end of the array instead of the beginning. So:

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items

Similarly, step may be a negative number:

a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed

Python is kind to the programmer if there are fewer items than you ask for. For example, if you ask for a[:-2] and a only contains one element, you get an empty list instead of an error. Sometimes you would prefer the error, so you have to be aware that this may happen.

Relationship with the slice object

A slice object can represent a slicing operation, i.e.:

a[start:stop:step]

is equivalent to:

a[slice(start, stop, step)]

Slice objects also behave slightly differently depending on the number of arguments, similar to range(), i.e. both slice(stop) and slice(start, stop[, step]) are supported. To skip specifying a given argument, one might use None, so that e.g. a[start:] is equivalent to a[slice(start, None)] or a[::-1] is equivalent to a[slice(None, None, -1)].

While the :-based notation is very helpful for simple slicing, the explicit use of slice() objects simplifies the programmatic generation of slicing.

2 of 13
729

The Python tutorial talks about it (scroll down a bit until you get to the part about slicing).

The ASCII art diagram is helpful too for remembering how slices work:

 +---+---+---+---+---+---+
 | P | y | t | h | o | n |
 +---+---+---+---+---+---+
   0   1   2   3   4   5
  -6  -5  -4  -3  -2  -1

One way to remember how slices work is to think of the indices as pointing between characters, with the left edge of the first character numbered 0. Then the right edge of the last character of a string of n characters has index n.

Discussions

A Comprehensive Guide to Slicing in Python
The start/end indexing when going in reverse has always taken a level of extra mental effort that I don't like. Like excluding the first and last item using [1:-1] is intuitive to me, but doing the same in reverse by doing [-2:0:-1] annoys me (though I do get why its like that). That is why I tend to do [1:-1][::-1] instead. More on reddit.com
๐ŸŒ r/Python
40
356
February 1, 2022
Slicing 2D Numpy arrays
You have to understand slices: they have the structure start:stop:step, where start tells you the index from where you'll get the values; stop tells you the next to last index for the values (meaning that your last index will be the previous one, not this), and step will give you the distance between elements. So, 1:2 tells you from the row 1 to the row 2 without including row 2. That gives you just row 1. More on reddit.com
๐ŸŒ r/PythonLearning
9
3
August 11, 2024
Python: Slicing lists

Nevermind I understand it now

More on reddit.com
๐ŸŒ r/learnprogramming
5
3
May 30, 2019
Help w slicing array distinctions

This is because the two expressions mean different things. You can think about a two-dimensional array as an array of arrays, something like this:

[
[_, _, _],
[_, _, _],
[_, _, _],
]

When you use the subscript you use, (btw. 0 is not necessary there and might be a bit confusing: a[0:, 2] == a[:, 2]), you say this:

Select all rows and then select the third element

and this is what gets selected:

[
[_, _, _],
[_, _, _],
[x, x, x],
]

However, when you do a[:, 2:], you are saying:

Select all rows, and then select the last column

And this is selected:

[
[_, _, x],
[_, _, x],
[_, _, x],
]

You would've been right to assume that these two should do the same, had it not being for the "direction" of rows.

More on reddit.com
๐ŸŒ r/learnpython
12
1
December 30, 2019
๐ŸŒ
Pythonhealthdatascience
pythonhealthdatascience.com โ€บ content โ€บ 01_algorithms โ€บ 03_numpy โ€บ 03_slicing.html
Array slicing and indexing โ€” Python for health data science.
Slicing and indexing are powerful ways to select and access elements within an array. The complexity of what you can achieve with numpy using only a small amount of code is quite remarkable. However, both approaches require careful study to avoid potential unexpected behaviour in your code (thatโ€™s a polite way of saying โ€˜bugsโ€™). We will cover this behaviour in detail, but for now its enough to say that slices can be considered views of an array rather than seperate objects.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-slicing-how-to-slice-an-array
Python Slicing โ€“ How to Slice an Array and What Does [::-1] Mean?
December 8, 2022 - It's also worth noting that the slicing action does not affect the original array. With slicing, you only "copy a portion" of the original array. For example, if you want to slice an array from a specific start value to the end of the array, here's how:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-slicing-multi-dimensional-arrays
Python Slicing Multi-Dimensional Arrays - GeeksforGeeks
July 1, 2026 - This produces a new 2-D array containing the last column values from every matrix. Slices can be used not only for reading data but also for updating multiple values at once. Python ยท import numpy as np matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) matrix[0:2, 0:2] = 0 print(matrix) Output ยท
Find elsewhere
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ numpy โ€บ array-slicing
NumPy Array Slicing
Array slicing is utilized when ... slicing syntax follows the format array[start:stop:step], where start is the index to begin the slice, stop is the index to end the slice (exclusive), and step defines the interval between elements....
๐ŸŒ
The Python Coding Stack
thepythoncodingstack.com โ€บ the python coding stack โ€บ a slicing story
A Slicing Story - by Stephen Gruppetta
June 25, 2024 - Slices create copies when dealing with lists, strings, tuples, and other built-in data types. However, this behaviour is not guaranteed by slicing, as you've seen in the case of NumPy arrays.
๐ŸŒ
Nanyang Technological University
libguides.ntu.edu.sg โ€บ python โ€บ arrayslicing
NP.4 Array Slicing - Python for Basic Data Analysis - LibGuides at Nanyang Technological University
1 month ago - Array slicing is similar to list slicing in Python. Array indexing also begins from 0. However, since arrays can be multidimensional, we have to specify the slice for each dimension. As we are mainly working with 2 dimensional arrays in this guide, we need to specify the row and column like ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
Slicing in NumPy is easy! โœ‚๏ธ - YouTube
#coding #numpy #python Slicing in NumPy allows you to extract portions of an array using a [start:stop:step] syntax. It works similarly to Python lists but ...
Published: July 27, 2025
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ user โ€บ basics.indexing.html
Indexing on ndarrays โ€” NumPy v2.5 Manual
The standard rules of sequence slicing apply to basic slicing on a per-dimension basis (including using a step index). Some useful concepts to remember include: The basic slice syntax is i:j:k where i is the starting index, j is the stopping index, and k is the step (\(k\neq0\)).
๐ŸŒ
YouTube
youtube.com โ€บ deeecode the web
How to Slice an Array in Python, with examples - YouTube
In this video, I simplify how to slice an array using different examples that shows the different ways arrays can be sliced in Python.Timestamp:00:00 Making ...
Published: December 9, 2022
Views: 328
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ a comprehensive guide to slicing in python
r/Python on Reddit: A Comprehensive Guide to Slicing in Python
February 1, 2022 - I've always found array slicing in python to be very powerful and useful, and a thing i wish more languages had. For my common use case (dealing with text) it's very fast to code something up. ... I'm very new to Python and one thing I find confusing and unintuitive is that some things, like slices, start counting at 0 but other things like groups in regular expressions start counting at 1.
๐ŸŒ
Problem Solving with Python
problemsolvingwithpython.com โ€บ 05-NumPy-and-Arrays โ€บ 05.06-Array-Slicing
Array Slicing - Problem Solving with Python
Where <slice> is the slice or section of the array object <array>. The index of the slice is specified in [start:stop]. Remember Python counting starts at 0 and ends at n-1. The index [0:2] pulls the first two values out of an array.
๐ŸŒ
TikTok
tiktok.com โ€บ @databy.fahad โ€บ video โ€บ 7626554115346222357
Numpy Indexing & Slicing for Data Science
TikTok - trends start here. On a device or on the web, viewers can watch and discover millions of personalized short videos. Download the app to get started.
๐ŸŒ
Python Central
pythoncentral.io โ€บ how-to-slice-listsarrays-and-tuples-in-python
How to Slice Lists/Arrays and Tuples in Python | Python Central
July 18, 2022 - A guide to slicing Python lists/arrays and Tuples, using multiple forms of syntax. We can use the short form of Python slicing, or the slice method.
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ numpy-array-slicing-in-python
NumPy Array Slicing in Python - StrataScratch
March 1, 2024 - You specify the start, stop, and step within square brackets to select a portion of the array. ... The first slice arr[:5] selects the first five elements of the array, demonstrating how omitting the start index defaults to 0.
๐ŸŒ
Reddit
reddit.com โ€บ r/pythonlearning โ€บ slicing 2d numpy arrays
r/PythonLearning on Reddit: Slicing 2D Numpy arrays
August 11, 2024 -

So,here I come again ๐Ÿคฃ

I don't get slicing in 2D..

In my lesson,I was taught that using this

d[1:2,1] 

means the 2nd element from the last two rows,and 2nd element from 1st column should be sliced..but when I use it I get only one element.Did I do something wrong?Can some of you awesome people hook me up with an explanation?

Here's some code for your palates:

a=[[1,2,3],[4,5,6],[7,8,9]]
import numpy as np
d=np.array(a)
d[1:2,1]
๐ŸŒ
Shishirkant
shishirkant.com โ€บ array-indexing-and-slicing-in-python
Array Indexing and Slicing in Python โ€“ Shishir Kant Singh
1. Basic Slicing and indexing : Consider the syntax x[obj] where x is the array and obj is the index. Slice object is the index in case of basic slicing.
๐ŸŒ
Medium
medium.com โ€บ @timothyjosephcw โ€บ what-is-python-slicing-and-how-does-slicing-in-python-work-2788632c5ba0
What is Python Slicing and How Does Slicing in Python Work? | by timothy joseph | Medium
August 22, 2024 - What is Python Slicing and How Does Slicing in Python Work? Python slicing, a versatile and creative technique, allows you to extract specific portions of sequences like lists, tuples, and strings โ€ฆ