In this article we will learn about NumPy Delete functions, we will explore their usage, benefits, and best practices, along with examples.
Deletion involves removing elements or entire sections from an array, thereby reducing its size. It facilitates data cleanup, filtering, and optimization of array structures.
NumPy Delete
np.delete()
: np.delete()
function removes specified elements or slices from an array along a given axis.arr = np.array([1, 2, 3, 4, 5])
deleted_arr = np.delete(arr, [1, 3])
print(deleted_arr)
np.delete()
function to delete the elements at indices [1, 3]
from the array arr
.deleted_arr
contains the elements of arr
with the elements at indices [1, 3]
removed.[1 3 5]
deleted_arr
after the deletion operation. The elements at indices [1, 3]
(i.e., 2
and 4
) have been removed from the original array arr
.arr = np.array([[1, 2, 3], [4, 5,6],[7,8,9]])
new_arr = np.delete(arr, 1, axis = 0)
print(new_arr)
np.delete()
function to delete the row at index 1
along axis 0
(rows) from the array arr
.[[1 2 3]
[7 8 9]]
new_arr
after the deletion operation. The row at index 1
(i.e., [4, 5, 6]
) has been removed from the original array arr
.arr = np.array([[1, 2, 3], [4, 5,6],[7,8,9]])
new_arr = np.delete(arr, 1, axis = 1)
print(new_arr)
np.delete()
function to delete the column at index 1
along axis 1
(columns) from the array arr
.[[1 3]
[4 6]
[7 9]]
new_arr
after the deletion operation. The column at index 1
(i.e., [2, 5, 8]
) has been removed from the original array arr
.In conclusion, the numpy.delete()
function offers a versatile solution for manipulating NumPy arrays, enabling users to efficiently remove specific elements or sub-arrays along designated axes. By mastering its syntax and capabilities, individuals can effectively manage and transform their data arrays, enhancing their data analysis workflows. As you explore the diverse applications of numpy.delete()
, consider sharing your newfound knowledge with others in the data science community. Sharing educational articles or tutorials on platforms like blogs, forums, or social media can contribute to the collective learning experience and foster collaboration among peers. Together, we can continue to expand our understanding of NumPy and its powerful array manipulation capabilities.
We hope that you liked our information, if you liked our information, then you must share it with your friends, family and group. So that they can also get this information.
Reference: np.delete()
Also Read:
Hi, I am Vishal Jaiswal, I have about a decade of experience of working in MNCs like Genpact, Savista, Ingenious. Currently i am working in EXL as a senior quality analyst. Using my writing skills i want to share the experience i have gained and help as many as i can.
SQL Interview Question at Zomato: These questions were recently asked in interview at Zomato, you…
Introduction: SQL Indexing and Query Optimization SQL indexing is a critical concept that can drastically…
This article is about the SQL Interview Questions asked by Walmart for their Data Analyst…
You must be able to answer these SQL Interview Questions if you are applying for…
This article tackles common SQL Interview Questions asked by EY, offering detailed solutions and explanations…
1164. Product Price at a Given Date: Learn how to track and select price from…