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 :: py hash 
Python :: clone keras model 
Python :: python check phone number 
Python :: use of kwargs and args in python classes 
Python :: loading in pyqt5 
Python :: pandas concat 
Python :: concatenation in python 3 
Python :: sendgrid send email to multiple recipients python 
Python :: python get pixel 
Python :: how to run python file from cmd 
Python :: tkinter dialog box 
Python :: python create dictionary from csv 
Python :: import discord 
Python :: cumulative frequency for python dataframe 
Python :: python compare objects 
Python :: update_or_create django 
Python :: python remove last instance of a list 
Python :: python match statement 
Python :: python callable type hint 
Python :: pandas read to a csv file 
Python :: python do something while waiting for input 
Python :: SciPy Convex Hull 
Python :: python circular import 
Python :: get country from city python 
Python :: code to take the picture 
Python :: get file size python 
Python :: isinstance function python 
Python :: how to join two dataframe in pandas based on two column 
Python :: python opencv measure distance two shapes 
Python :: global in python 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =