Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy compare arrays

bool isEqual = numpy.array_equal(Array1, Array2)
Comment

numpy arrays equality

np.array_equal(A,B)  # test if same shape, same elements values
np.array_equiv(A,B)  # test if broadcastable shape, same elements values
np.allclose(A,B,...) # test if same shape, elements have close enough values
Comment

numpy compare

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

PREVIOUS NEXT
Code Example
Python :: reindex pandas dataframe from 0 
Python :: python keylogger 
Python :: python get majority of list 
Python :: count number of islands python 
Python :: how to find the most frequent value in a column in pandas dataframe 
Python :: install python glob module in windows 
Python :: pretty print pandas dataframe 
Python :: install re package python 
Python :: python password generator 
Python :: python format 2 digits 
Python :: matplotlib label axis 
Python :: count missing values by column in pandas 
Python :: install googlesearch for python 
Python :: pandas drop row by condition 
Python :: pandas to csv without header 
Python :: discord py on ready 
Python :: python tk fullscreen 
Python :: open url python 
Python :: open choose files from file explorer python 
Python :: np.argsort reverse 
Python :: Install requests-html library in python 
Python :: pil get image size 
Python :: get last year of today python 
Python :: capture output of os.system in python 
Python :: py get days until date 
Python :: squared sum of all elements in list python 
Python :: df from numpy array 
Python :: django docs case when 
Python :: kivy fixed window 
Python :: dictionary from two columns pandas 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =