How to remove a column from NumPy array

You can remove a column from the NumPy array with the following code. If you want to learn Python, I highly recommend reading This Book.

# Import the NumPy library as np
import numpy as np

# Initialize a NumPy Array
a = np.array([[1, 2, 3, 4],[5, 10, 15, 20]])

# Remove 3rd column of NumPy Array
b = np.delete(a, 2, 1)

# Display the output
print(b)

Output:

[[ 1  2  4]
 [ 5 10 20]]

Free Learning Resources

Leave a Comment

Your email address will not be published.