In your array:

  • The x and t, are the beginning of the slice;
  • The y and t, are the end of the slice;
  • The i and m, are the step of the slice.

For example, let's define an 8x8 array:

z=[[x*y+x+y for x in range(8)] for y in range(8)]
z=np.asarray(z)

Out[1]:
array([[ 0,  1,  2,  3,  4,  5,  6,  7],
       [ 1,  3,  5,  7,  9, 11, 13, 15],
       [ 2,  5,  8, 11, 14, 17, 20, 23],
       [ 3,  7, 11, 15, 19, 23, 27, 31],
       [ 4,  9, 14, 19, 24, 29, 34, 39],
       [ 5, 11, 17, 23, 29, 35, 41, 47],
       [ 6, 13, 20, 27, 34, 41, 48, 55],
       [ 7, 15, 23, 31, 39, 47, 55, 63]])

z.shape
Out[2]: (8, 8)

From row 0 until row 3 (excluding it) every 2 rows, will index like:

z[0:3:2]

Out[3]: 
array([[ 0,  1,  2,  3,  4,  5,  6,  7],
       [ 2,  5,  8, 11, 14, 17, 20, 23]])

For columns:

z[:,1:6:3]

Out[4]: 
array([[ 1,  4],
       [ 3,  9],
       [ 5, 14],
       [ 7, 19],
       [ 9, 24],
       [11, 29],
       [13, 34],
       [15, 39]])

Combining rows and columns:

z[0:3:2, 0:3:2]

Out[5]: 
array([[0, 2],
       [2, 8]])
Answer from Pedro on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › home › python_data_structure › python 2d array
Understanding Python 2D Arrays
February 21, 2009 - We can update the entire inner array or some specific data elements of the inner array by reassigning the values using the array index.
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › AccessingDataAlongMultipleDimensions.html
Accessing Data Along Multiple Dimensions in an Array — Python Like You Mean It
# providing two numbers to access an element # in a 2D-array >>> grades[1, 0] # Brad's score on Exam 1 84 # negative indices work as with lists/tuples/strings >>> grades[-2, 0] # Brad's score on Exam 1 84 · We can also uses slices to access subsequences of our data. Suppose we want the scores of all the students for Exam 2. We can slice from 0 through 3 along axis-0 (refer to the indexing diagram in the previous section) to include all the students, and specify index 1 on axis-1 to select Exam 2:
Discussions

python - How to index using through 2d arrays? - Stack Overflow
Can someone please explain to me how numpy indexing works for 2d arrays. I am finding it difficult to wrap my head around. Specifically, if i create a 2d 8x8 array, what would each value represent in More on stackoverflow.com
🌐 stackoverflow.com
Help finding the index of a given value within a 2D array
Numpy is a great and powerful tool, but this is not one of the things it's good at. It would be much better for you to store the player's actual position, rather than searching for the player in a map. But if you really really want to: the function you want is np.argwhere. More on reddit.com
🌐 r/learnpython
3
1
November 13, 2022
Is it possible to access multidimensional numpy array with a single index without a reshape?
But is there a property or a trick to access the elements with one index without using a reshape? I mean, it's a 2D array. Accessing it via a 1D index is reshaping it. More on reddit.com
🌐 r/learnpython
4
1
June 30, 2023
Confusion about index ordering for 2d arrays.
I know nothing of computer science but use Julia and have used other languages in my job (economist), and all previous languages I have used (Matlab fortran etc) have worked this way. This makes sense to me as it is how I would index elements of a matrix or tensor in the context of linear algebra. More on reddit.com
🌐 r/Julia
10
12
November 22, 2020
🌐
NumPy
numpy.org › devdocs › user › basics.indexing.html
Indexing on ndarrays — NumPy v2.5.dev0 Manual
The simplest case of indexing with N integers returns an array scalar representing the corresponding item. As in Python, all indices are zero-based: for the i-th index \(n_i\), the valid range is \(0 \le n_i < d_i\) where \(d_i\) is the i-th element of the shape of the array.
🌐
Programiz
programiz.com › python-programming › numpy › array-indexing
Numpy Array Indexing (With Examples)
In NumPy, we can access specific rows or columns of a 2-D array using array indexing. Let's see an example. import numpy as np # create a 2D array array1 = np.array([[1, 3, 5], [7, 9, 2], [4, 6, 8]]) # access the second row of the array second_row = array1[1, :] print("Second Row:", second_row) # Output: [7 9 2] # access the third column of the array third_col = array1[:, 2] print("Third Column:", third_col) # Output: [5 2 8]
🌐
Quora
quora.com › How-do-I-return-the-index-of-an-element-in-a-2D-array-in-Python
How to return the index of an element in a 2D array in Python - Quora
Answer (1 of 2): You don’t return the index - your code needs to keep track of where the elements are. If you are asking how do you search a 2D array - the only way is something like this: [code]def find_all(matrix, element): """Iterate through all row, column indexes in a 2D Matrix where ...
🌐
Reddit
reddit.com › r/learnpython › help finding the index of a given value within a 2d array
r/learnpython on Reddit: Help finding the index of a given value within a 2D array
November 13, 2022 -

Been messing around with numpy, trying to familiarize myself with it and seeing how I'd be able to utilize its arrays to store (very simple) map data for this text adventure game I've been working on. So far it seems like it'd be pretty darn useful, but I seem to have run into something of an issue.

My code is as follows (note: this is purposefully made with out a main class, because I am just trying to get the basic functionality down in my head before I incorporate it into my main program, and this is just easier for me):

# import numpy module as np
import numpy as np

# Establish the game map, a 3x3 grid of 0's
mainarray = np.array([[0, 0, 0],
                      [0, 0, 0],
                      [0, 0, 0]])

# Give feedback to make console easier to read
print(mainarray)
print("")
print("Placing player in center...")

# Place player on map (represented by a value of 1)
mainarray[1, 1] = 1

print(mainarray)

print("")
print("Locating player...")

# Attempt to find what the current index is of the value 1
print("")
print("Player is at index: ", np.where(mainarray == 1)[0][0])

In my head, I would like to eventually use this np.where() function (if I can) in one of the functions that moves my character. What I want to do is grab the current index of the "player" (represented by the number 1) and attempt to change that value to a 0, and change the value at an adjacent index to 1 (the tile that the player is moving to). Basically, I would like to use each index of the array as a sort of coordinate that I can take and use to move this "1" around the array, setting each index back to "0" after moving the "1", all based off user input.

Anyways, I am not getting any errors, however, the result that gets printed to the console is:

Player is at index:  1

Why is it just one number? It remains the same, even when I remove that second [0] in the last line. I don't fully understand how this function works, as this is the first time I've tried to use it, but since there are no errors, I have no clue what is going on.

Shouldn't I be receiving an index with two values, one for the column and one for the row? If not, how can I grab that as a result and use it in the way I described above? Is it even possible, or am I barking up the wrong tree with this function?

Find elsewhere
🌐
Drbeane
drbeane.github.io › python_dsci › pages › array_2d.html
2-Dimensional Arrays — Python for Data Science
The first number indexes a row in the array and the second number indexes a column. ... We can also use slicing with 2D arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › python › indexing-multi-dimensional-arrays-in-python-using-numpy
Indexing Multi-dimensional arrays in Python using NumPy - GeeksforGeeks
November 4, 2025 - Indexing in multi-dimensional arrays allows us to access, modify or extract specific elements or sections from arrays efficiently. In Python, NumPy provides tools to handle this through index numbers, slicing and reshaping.
🌐
AskPython
askpython.com › home › array indexing in python – beginner’s reference
Array Indexing in Python - Beginner's Reference - AskPython
February 22, 2021 - Here, <value> means the variable where the retrieved element from the array is stored. And [row, column] specifies the row and column index of the value. Construct a 2D array and retrieve one element using array index.
🌐
Uni-heidelberg
ita.uni-heidelberg.de › ~dullemond › lectures › python_2019 › py4sci_wed › Note on IndexOrdering.html
Index ordering in Numpy
Now things get really confusing! As you see, the index order is now: y,x,z, while the argument order to meshgrid() remains x,y,z. Therefore, for 3-D and higher-dimensional arrays, I recommend always to use indexing='ij'!
🌐
Medium
medium.com › @whyamit404 › basics-of-numpy-array-indexing-9052e6d6b5cf
Basics of NumPy Array Indexing. If you think you need to spend $2,000… | by whyamit404 | Medium
February 9, 2025 - Here’s a trick you’ll love — negative indexing. It allows you to access elements starting from the end of the array. Think of it as reaching for the last slice of pizza instead of the first one. # Accessing the last element in a 1D array print(arr[-1]) # Output: 40 (last element) # Accessing elements from the end in a 2D array print(matrix[-1, -2]) # Output: 8 (last row, second-to-last column)
🌐
DataCamp
campus.datacamp.com › courses › introduction-to-python-for-finance › arrays-in-python
2D arrays and functions | Python
To subset an element in the second ... Remembering that Python is zero-indexed, the first index represents the element in the first dimension or row and the second index represents the element in the second dimension or column....
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-indexing
Numpy Array Indexing - GeeksforGeeks
December 17, 2025 - A 1D NumPy array is a sequence of values with positions called indices which starts at 0. We access elements by using these indices in square brackets like arr[0] for the first element.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
Python creates only one inner list and one 0 object, not separate copies. This shared reference behavior is known as shallow copying (aliasing). If we assign the 0th index to another integer say 1, then a new integer object is created with the value of 1 and then the 0th index now points to this new int object as shown below · Similarly, when we create a 2d array as "arr = [[0]*cols]*rows" we are essentially extending the above analogy.
Published   December 20, 2025
🌐
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, but excludes the end index. Slice elements from index 4 to the end of the array:
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_indexing.asp
NumPy Array Indexing
The second number represents the ... 4 5 6 Since we selected 2, we end up with the third value: 6 · Use negative indexing to access an array from the end....
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
The optional arguments start and end are interpreted as in the slice notation and are used to limit the search to a particular subsequence of the list. The returned index is computed relative to the beginning of the full sequence rather than ...
🌐
NumPy
numpy.org › doc › stable › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.4 Manual
As with built-in Python sequences, NumPy arrays are “0-indexed”: the first element of the array is accessed using index 0, not 1.