How to drop a column in NumPy array

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

How to drop a column in NumPy array
How to drop a column in the NumPy array
import numpy as np

# Original Array
a = np.array([[1, 2, 3, 4, 5],[10, 15, 20, 25, 30],[2, 4, 6, 8, 10]])

# drop fourth column
b = np.delete(a, 3, 1)

# display new array
print(b)

Output

[[ 1  2  3  5]
 [10 15 20 30]
 [ 2  4  6 10]]

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.