Answers for "Python NumPy delete Function Example Deletion performed using Boolean Mask"

0

Python NumPy delete Function Example Deletion performed using Boolean Mask

# welcome to softhunt.net
# Python Program illustrating
# numpy.delete()

import numpy as np

arr = np.arange(5)
print("Original array : ", arr)
mask = np.ones(len(arr), dtype=bool)

# Equivalent to np.delete(arr, [0,2,4], axis=0)
mask[[0,2]] = False
print("\nMask set as : ", mask)
result = arr[mask,...]
print("\nDeletion Using a Boolean Mask : ", result)
Posted by: Guest on April-25-2022

Python Answers by Framework

Browse Popular Code Answers by Language