The simplest way to delete rows and columns from arrays is the numpy.delete method.

Suppose I have the following array x:

x = array([[1,2,3],
        [4,5,6],
        [7,8,9]])

To delete the first row, do this:

x = numpy.delete(x, (0), axis=0)

To delete the third column, do this:

x = numpy.delete(x,(2), axis=1)

So you could find the indices of the rows which have a 0 in them, put them in a list or a tuple and pass this as the second argument of the function.

Answer from Jaidev Deshpande on Stack Overflow
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Delete rows/columns from an array with np.delete() | note.nkmk.me
February 5, 2024 - Specify the row or column numbers with a list. a = np.arange(12).reshape(3, 4) print(a) # [[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] print(np.delete(a, [0, 2], 0)) # [[4 5 6 7]] print(np.delete(a, [0, 3], 1)) # [[ 1 2] # [ 5 6] # [ 9 10]] ... Starting from NumPy version 1.19, a list or array of Boolean values can be treated as a mask, with the indexes corresponding to True being deleted.
Discussions

Faster way to delete numpy array rows than numpy.delete?
Why delete them at all? Just index your array. a[a.any(axis=1)] Breakdown: In [204]: a Out[204]: array([[1, 2], [0, 0], [1, 0], [5, 5], [0, 0]]) In [205]: a.any(axis=1) # checks if there are ANY nonzero values on each row Out[205]: array([ True, False, True, True, False], dtype=bool) In [206]: a[a.any(axis=1)] Out[206]: array([[1, 2], [1, 0], [5, 5]]) Deleting rows one by one means removing that element from the array, and going to each subsequent element and shifting it down one in the array. For each single delete. Instead, if you just boolean index, then you're creating just a view of the data which you can assign to a new array so you don't have to one by one shift the whole array a bunch of times. More on reddit.com
🌐 r/learnpython
5
3
December 19, 2018
python - Delete rows at select indexes from a numpy array - Stack Overflow
9 pythonic way to delete elements from a numpy array More on stackoverflow.com
🌐 stackoverflow.com
Deleting rows and columns from numpy arrays
A numpy array cannot be resized. If you delete a column or row what you actually doing is creating a new numpy array of a reduced size and copying all the data over. This is very slow. So most likely you'd be much better off using a python list instead, which also simplifies the delete function. Is there a reason you want to use numpy? More on reddit.com
🌐 r/learnpython
5
3
March 19, 2024
how can I remove rows from a numpy array based on a condition
You can use Boolean arrays as index masks. Say you have: >>> import numpy as np >>> M = np.array([[1,2], [3,4],[5,6]]); a = np.array([1, 3]) >>> M == a array([[ True, False], [False, False], [False, False]]) Because of the Numpy's broadcasting rules, a is compared with each row of M. We can apply some sort of reduction to each row: >>> (M == a).any(axis=1) array([ True, False, False]) In your case, you want to remove rows that match this condition, which means you want to keep rows that match the complementary condition, so one of these: >>> ~(M == a).any(axis=1) array([False, True, True]) >>> (M != a).all(axis=1) array([False, True, True]) And you can use that as an index: >>> M[(M != a).all(axis=1)] array([[3, 4], [5, 6]]) More on reddit.com
🌐 r/learnpython
2
1
February 27, 2023
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.delete.html
numpy.delete — NumPy v2.2 Manual
>>> import numpy as np >>> arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) >>> arr array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]]) >>> np.delete(arr, 1, 0) array([[ 1, 2, 3, 4], [ 9, 10, 11, 12]])
🌐
DataCamp
datacamp.com › doc › numpy › delete-numpy
NumPy delete()
This example removes the element at index `2` from the 1D array, resulting in `[1, 2, 4, 5]`. import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) new_arr = np.delete(arr, 1, axis=0) print(new_arr) Here, the second row (index `1`) is deleted from a 2D array, resulting in `[[1, 2, 3], [7, 8, 9]]`.
🌐
Delft Stack
delftstack.com › home › howto › numpy › python numpy delete row
How to Delete Row in NumPy | Delft Stack
March 14, 2025 - By calling np.delete(array, 1, axis=0), we remove the row at index 1, which corresponds to the second row of the original array. The axis=0 parameter indicates that we are working along the rows.
🌐
Tutorialsinhand
tutorialsinhand.com › https://tutorialsinhand.com › articles › how-to-delete-rows-from-a-numpy-array
delete a row from a numpy array | delete multiple rows in numpy array
June 17, 2022 - This will delete rows based on the given range. It will delete rows from start row to end row specified. ... 2. slice() function - start_row specifies the starting row position and end_row specifies the ending row position ... In this example, we will delete rows in the numpy array.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-delete-python
numpy.delete() in Python - GeeksforGeeks
January 23, 2026 - import numpy as np arr = np.arange(12).reshape(3, 4) print("Array:\n", arr) print("Shape:", arr.shape) # Delete row at index 1 a = np.delete(arr, 1, axis=0) print("\nAfter deleting row 1:\n", a) print("Shape:", a.shape) # Delete column at index 1 b = np.delete(arr, 1, axis=1) print("\nAfter deleting column 1:\n", b) print("Shape:", b.shape)
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › delete-rows-and-columns-of-numpy-ndarray
Delete rows and columns of NumPy ndarray - GeeksforGeeks
April 21, 2021 - In this article, we will discuss how to delete the specified rows and columns in an n-dimensional array. We are going to delete the rows and columns using numpy.delete() method.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-delete-multiple-rows-of-numpy-array
How to delete multiple rows of NumPy array ? - GeeksforGeeks
January 9, 2023 - For doing our task, we will need some inbuilt methods provided by the NumPy module which are as follows: np.delete(ndarray, index, axis): Delete items of rows or columns from the NumPy array based on g
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › delete()
Python Numpy delete() - Remove Elements
November 6, 2024 - Execute the numpy.delete() function with these indices. ... Here, elements at indices 1, 3, 5—corresponding to 1, 3, 5 respectively—are deleted from array_md. Specify the axis along which the deletion is to take place: 0 for rows and 1 for ...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-remove-rows-from-a-numpy-array-based-on-multiple-conditions
How to remove rows from a Numpy array based on multiple conditions ? | GeeksforGeeks
July 3, 2021 - For doing our task, we will need some inbuilt methods provided by the NumPy module which are as follows: np.delete(ndarray, index, axis): Delete items of rows or columns from the NumPy array based on given index conditions and axis specified, ...
🌐
CodeSpeedy
codespeedy.com › home › delete a row from a numpy matrix in python
Delete a row from a NumPy matrix in Python - CodeSpeedy
February 7, 2023 - Simply, create a two-dimensional array (4 rows, 5 columns) with NumPy, delete the specified row with help of the method np.delete() which is mentioned above in the tutorial, and then create the second array with NumPy.
🌐
YouTube
youtube.com › watch
numpy.delete() - Delete elements / rows / columns from Numpy Array in Python - YouTube
Learn how to delete elements from numpy array by index positions. Topics covered,1.) Delete single element from Numpy Array by index position.2.) Delete mult...
Published: December 28, 2020
🌐
w3resource
w3resource.com › numpy › manipulation › delete.php
NumPy: numpy.delete() function - w3resource
April 25, 2026 - Next, the np.delete() function is used to remove the second row (index 1) from arr by specifying 1 as the index to be deleted and 0 as the axis along which to delete (i.e., the row axis).
🌐
Reddit
reddit.com › r/learnpython › deleting rows and columns from numpy arrays
r/learnpython on Reddit: Deleting rows and columns from numpy arrays
March 19, 2024 -

I have this numPlayers-long list of numpy arrays called payoffMatrix. That is, payoffMatrix[x] is a numpy array. Given this removeStrategy function:

def removeStrategy(self, player, s):
        """Removes strategy s from player in the payoff matrix

        Args:
            player (int): index of the player
            s (int): index of the strategy
        """
        if player == 0: # player is player 1
            for x in range(self.numPlayers):
                if self.numPlayers < 3:
                    # deleting s-th row from every x-th matrix
                    self.payoffMatrix[x] = np.delete(self.payoffMatrix[x], s, axis=0)
                else:
                    for ar in self.payoffMatrix[x]:
                        ar = np.delete(ar, s, axis=0)
        elif player == 1: # player is player 2
            for x in range(self.numPlayers):
                if self.numPlayers < 3:
                    # deleting s-th column from every x-th matrix
                    self.payoffMatrix[x] = np.delete(self.payoffMatrix[x], s, axis=1)
                else:
                    for ar in self.payoffMatrix[x]:
                        ar = np.delete(ar, s, axis=1)
        else: # player > 1
            (...)
                
        # Decrement the number of strategies for player
        self.players[player].numStrats -= 1

        return

the following works as expected:

arr_2players = np.array([
    [
        [1, 2],
        [3, 4]
    ],
    [
        [5, 6],
        [7, 8]
    ]
])

G = simGame(2)
G.enterPayoffs(arr_2players, 2, [2, 2])
G.removeStrategy(0, 1)
G.print()

output:

[[1 2]]

[[5 6]]

The following doesn't work:

arr_3players = np.array([
    [ # player 1's matrices
        [
            [1, 1],
            [1, 1],
        ],
        [
            [1.1, 1.1],
            [1.1, 1.1]
        ]
    ],
    [ # player 2's matrices
        [
            [2, 2], 
            [2, 2]
        ],
        [
            [2.1, 2.1], 
            [2.1, 2.1]
        ]
    ],
    [ # player 3's matrices
        [
            [3, 3], 
            [3, 3]
        ],
        [
            [3.1, 3.1], 
            [3.1, 3.1]
        ]
    ]
])
G = simGame(3)
G.enterPayoffs(arr_3players, 3, [2, 2, 2])
G.removeStrategy(0, 1)
G.print()

The output is the same as arr_3players. The expected output is

[[[1.  1. ]]

 [[1.1 1.1]]]

[[[2.  2. ]]

 [[2.1 2.1]]]

[[[3.  3. ]]

 [[3.1 3.1]]]

I also need it to be capable of deleting columns in these matrices (i.e., when player == 1). For instance,

G = simGame(3)
G.enterPayoffs(arr_3players, 3, [2, 2, 2])
G.removeStrategy(1, 1)
G.print()

should result in something like

[[[1.]  
  [1.]] 

 [[1.1]  
  [1.1]]]

[[[2.] 
  [2.]]

 [[2.1]
  [2.1]]]

[[[3.]
  [3.]]

 [[3.1]
  [3.1]]]

The problem seems to be that when there are more than 2 players, the matrices are nested one set of brackets deeper in the numpy array. Is there a way to make this work?

🌐
Pythontutorials
pythontutorials.net › blog › numpy-delete-row-from-array
Mastering Row Deletion in NumPy Arrays | PythonTutorials.net
June 21, 2025 - We can also delete multiple rows at once by passing a list of indices to the np.delete() function. import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) # Delete the first and third rows (indices 0 and 2) new_arr = np.delete(arr, [0, 2], axis = 0) print("Original ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.delete.html
numpy.delete — NumPy v2.5 Manual
>>> import numpy as np >>> arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) >>> arr array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]]) >>> np.delete(arr, 1, 0) array([[ 1, 2, 3, 4], [ 9, 10, 11, 12]])