Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy delete

import numpy as np

arr = np.array([1, 2, 1, 2,  3, 4, 5, 4, 6, 7])
# create a set array with no duplicates
arr = np.unique(arr)
print(arr)
# [1 2 3 4 5 6 7]

arr1 = np.array([1, 2, 3, 4])
arr2 = np.array([3, 4, 5, 6])

# create a 1d set array without from both arrays removing duplicates
arr = np.union1d(arr1, arr2)
print(arr)
# output [1 2 3 4 5 6]

arr1 = np.array([1, 2, 3, 4])
arr2 = np.array([3, 4, 5, 6])

# create a 1d set array where both numbers are found in both arrays
arr = np.intersect1d(arr1, arr2, assume_unique=True)
print(arr)
# output [3 4]

arr1 = np.array([1, 2, 3, 4])
arr2 = np.array([3, 4, 5, 6])

# create a 1d set array that contained only numbers found in the first array but not the second
arr = np.setdiff1d(arr1, arr2, assume_unique=True)
print(arr)
# output [1 2]

arr1 = np.array([1, 2, 3, 4])
arr2 = np.array([3, 4, 5, 6])

# create a 1d set array where numbers from both arrays are not in each other
arr = np.setxor1d(arr1, arr2, assume_unique=True)

print(arr)
# output [1 2 5 6]

Comment

Python NumPy delete Function Syntax

numpy.delete(array, object, axis = None)
Comment

Python NumPy delete Function Example

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

import numpy as np

#Working on 1D
arr = np.arange(12).reshape(3, 4)
print("arr : 
", arr)
print("Shape : ", arr.shape)

# deletion from 2D array
a = np.delete(arr, 1, 0)
'''
		[[ 0 1 2 3]
		[ 4 5 6 7] -> deleted
		[ 8 9 10 11]]
'''
print("
deleteing arr 2 times : 
", a)
print("Shape : ", a.shape)

# deletion from 2D array
a = np.delete(arr, 1, 1)
'''
		[[ 0 1* 2 3]
		[ 4 5* 6 7]
		[ 8 9* 10 11]]
			^
			Deletion
'''
print("
deleteing arr 2 times : 
", a)
print("Shape : ", a.shape)
Comment

PREVIOUS NEXT
Code Example
Python :: how to pass multiple parameters by 1 arguments in python 
Python :: expand pandas dataframe into separate rows 
Python :: conv2d default stride 
Python :: feature engineering data preprocessing 
Python :: python pip 
Python :: circular dependencies in python 
Python :: program to replace lower-case characters with upper-case and vice versa in python 
Python :: how to convert tensorflow 1.15 model to tflite 
Python :: topological sort 
Python :: python strip() 
Python :: attributes in python 
Python :: python upload file to s3 
Python :: plot scattered dataframe 
Python :: insert blank row in data frame 
Python :: prime numbers upto n in python 
Python :: run python module from command line 
Python :: push button raspberry pi 
Python :: why is c++ faster than python 
Python :: loops in python 
Python :: unknown amount of arguments discord py 
Python :: python dict delete key 
Python :: plt.hist bins 
Python :: python strip function 
Python :: python list comprehension with filter 
Python :: numpy linspace function 
Python :: object oriented programming python 
Python :: set intersection 
Python :: How to split a string into a dictionary in Python 
Python :: how to convert time from one timezone to another in python 
Python :: merge sorting algorithm 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =