In Python, the indexing operation for a type is implemented by the __getitem__/__setitem__/__delitem__ magic methods. To understand how indexing syntax is interpreted, and thus how these methods are called, we can simply define our own class:

class test:
    def __getitem__(self, idx):
        return idx

test()[:, [1,2,3], ...]
# result: (slice(None, None, None), [1, 2, 3], Ellipsis)

This slice type is a built-in type mentioned earlier in the same documentation, with a link to more specific information.

Ellipsis is simply the name of the object created by the literal syntax .... It's what Numpy uses to represent the complete extent of any number of axes - so this lets us avoid worrying about the dimensionality of the array we're working with.

The important thing to realize is that we can use that same index tuple directly, to get the same result.

Thus, given a dimension along which to slice with [ci], we can construct the necessary tuple, and index with it:

all = slice(None)
def make_index(ci, dimension):
    return (all,) * dimension + ([ci], Ellipsis)

# Now we can do things like:
arr[make_index(ci, dimension)] = some_data
Answer from Karl Knechtel on Stack Overflow
🌐
IncludeHelp
includehelp.com › python › array-slice-with-comma.aspx
Python - Array slice with comma
# Import numpy import numpy as np # Creating a numpy array arr = np.array([[ 1, 2, 3],[ 4, 5, 6],[ 7, 8, 9]]) # Display original array print("Original array:\n",arr,"\n") # Slicing the array using comma res = arr[1,1] # Display result print("Result:\n",res) In this example, we have used the following Python basic topics that you should learn:
🌐
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 16
6670

The syntax is:

Use with AIa[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:

Use with AIa[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:

Use with AIa[-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:

Use with AIa[::-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.:

Use with AIa[start:stop:step]

is equivalent to:

Use with AIa[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 16
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:

Use with AI +---+---+---+---+---+---+
 | 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.

🌐
Pythonhealthdatascience
pythonhealthdatascience.com › content › 01_algorithms › 03_numpy › 03_slicing.html
Array slicing and indexing — Python for health data science.
Going back to slicing we can understand the dimensions. Here’s a reminder fo the full array: ... Task: slice td so that we have the vector [13, 23, 33] i.e. the [i, 1, 0] elements where i is the row.
🌐
The Python Coding Stack
thepythoncodingstack.com › notes from the near future › a slicing story
A Slicing Story - The Python Coding Stack
September 24, 2023 - Now, let's replicate these steps using NumPy arrays. You'll need to install NumPy using pip install numpy or your favourite package manager: The behaviour when you slice a NumPy array is different to the case when you slice a list. When you assign a new value to an item in subset_of_numbers_array, the original array also changes.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
Explanation: slice starts at index 1 and stops before index 4, returning the elements at indices 1, 2, and 3.
Published: July 16, 2026
Find elsewhere
🌐
Nanyang Technological University
libguides.ntu.edu.sg › python › arrayslicing
NP.4 Array Slicing - Python for Basic Data Analysis - LibGuides at Nanyang Technological University
August 26, 2026 - 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 ...
🌐
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:
🌐
Railsware
railsware.com › home › engineering › indexing and slicing for lists, tuples, strings, other sequential types in python
Python Indexing and Slicing for Lists, Tuples, Strings, other Sequential Types | Railsware Blog
September 28, 2026 - Slice assignment (nums[:4] = [1,2,3]) can substitute, extend, shrink, or replace every nth element in place, but when a step is used, the replacement list must match the selected length exactly or Python raises a ValueError. The article positions itself as groundwork for indexing/slicing in NumPy arrays ...
🌐
StrataScratch
stratascratch.com › blog › numpy-array-slicing-in-python
NumPy Array Slicing in Python - StrataScratch
March 1, 2024 - The basic syntax for array slicing in NumPy follows the format: array[start:stop:step]. Here's what each part means: start: The index at which the slice starts.
🌐
Python.org
discuss.python.org › ideas › array slicing notation to get n elements from index i
Array slicing notation to get N elements from index I - Ideas - Discussions on Python.org
April 24, 2023 - Hi - my first post here 🙂 I’ve had a search through PEPs, forums, and at work but haven’t been able to prove the negative that this syntactic sugar doesn’t exist. Frequently I need to get an array slice in the form: arr[start_idx:(start_idx + some_length)] The repetition of the start_idx ...
🌐
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 ·
🌐
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....
🌐
Sentry
sentry.io › sentry answers › python › python slice notation
Python Slice Notation for Strings and Lists | Sentry
September 17, 2026 - Slicing segments an array and returns that segment. In the example below, a string is segmented to return a single word from within the string: hello_world_string = "Hello World!" world = hello_world_string[7:12] print(world) ...
🌐
Reddit
reddit.com › r/learnpython › numpy array slicing view vs copy confusion
r/learnpython on Reddit: Numpy array slicing view vs copy confusion
August 3, 2021 -

I'm making a program that does some processing for material dispersal in bomb explosions, working on numpy arrays to be converted into geo raster files and eventually displayed in ArcGIS.

It was my understanding that a slice of a numpy array is a view, and so altering the data on it should alter it on the original array. But I keep returning arrays with all zero values. If this is not the case, I can't seem to find any easy way to apply a function to just a part of a multidimensional array.

Here is the part of the code in question.

🌐
Lkhibra
lkhibra.ma › books › Python-for-Data-Analysis.pdf pdf
Python for Data Analysis Data Wrangling with pandas, NumPy & Jupyter
Python · for Data Analysis · Data Wrangling with pandas, NumPy & Jupyter · Wes McKinney · Third · Edition
🌐
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
🌐
Python Morsels
pythonmorsels.com › slicing
Python list slicing (with examples) - Python Morsels
August 3, 2026 - In Python, slicing uses colons in square brackets to grab part of a list, string, or tuple: first items, last items, reverse, and step.