![]() |
VOOZH | about |
The numpy.delete() function returns a new array with the deletion of sub-arrays along with the mentioned axis.
[10 30 40]
Here, the element at index 1 is removed from the array.
numpy.delete(array, object, axis = None)
Parameters:
Return: A new NumPy array with the specified elements removed.
Let's look at some of the examples:
('Array:', array([0, 1, 2, 3, 4]))
('Shape:', (5,))
Deleting index 2: [0 1 3 4]
('Shape:', (4,))
Deleting indices [1, 2]: [0 3 4]
('Shape:', (3,))
Explanation:
Output:
Array:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
Shape: (3, 4)
After deleting row 1:
[[ 0 1 2 3]
[ 8 9 10 11]]
Shape: (2, 4)
After deleting column 1:
[[ 0 2 3]
[ 4 6 7]
[ 8 10 11]]
Shape: (3, 3)
Explanation:
('Original array:', array([0, 1, 2, 3, 4]))
('Mask:', array([False, True, False, True, True]))
('After deletion:', array([1, 3, 4]))
Explanation: