Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy merge arrays

>>> a = np.array([[1, 2], [3, 4]])
>>> b = np.array([[5, 6]])
>>> np.concatenate((a, b), axis=0)
array([[1, 2],
       [3, 4],
       [5, 6]])
>>> np.concatenate((a, b.T), axis=1)
array([[1, 2, 5],
       [3, 4, 6]])
Comment

numpy merge

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 :: python hash() seed 
Python :: generate rsa key python 
Python :: extract text from pdf python 
Python :: python declare variable type array 
Python :: how to make a loading gif in pyqt5 
Python :: how to make python open an application on mac 
Python :: list comprehension python if else 
Python :: python visualize fft of an image 
Python :: copy content from one file to another in python 
Python :: UnicodeDecodeError: ‘utf8’ codec can’t decode byte 
Python :: how to take space separated input in python 
Python :: python logging 
Python :: get number of key in dictionary python 
Python :: save model history keras 
Python :: df astype 
Python :: undefined in python 
Python :: parentheses in python 
Python :: python string to lower 
Python :: python generate pdf from template 
Python :: how to clear dictionary in python 
Python :: python program to print the fibonacci sequence 
Python :: beautiful soap python get the link online 
Python :: Python Overloading the + Operator 
Python :: Python NumPy broadcast_arrays() Function Example 
Python :: PY | websocket - server 
Python :: rename column in pandas with second row 
Python :: information of environment variables in python 
Python :: randint() 
Python :: py -m pip 
Python :: how to get python list length 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =