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

join two numpy arrays

numpy.concatenate([arr1, arr2]) # Joining arr1 and arr2
Comment

Concatenate 2 array numpy


a = np.array([1, 2, 3, 4])
b = np.array([5, 6, 7, 8])
np.concatenate((a, b))
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

numpy concatenation array

#// required library
import numpy as npy

#// define 3 (1D) numpy arrays
arr1 = npy.array([10, 20, 30])
arr2 = npy.array([40, 50, 60])
arr3 = npy.array([70, 80, 90])

arrCon = npy.concatenate([arr1, arr2, arr3])
print(arrCon)

#// concatenation can also happen with 2D arrays
arr1_2d = npy.array([
  [10, 20, 30],
  [40, 50, 60]
])
arr2_2d = npy.array([
  [11, 22, 33],
  [44, 55, 66]
])

arr_2dCon = npy.concatenate([arr1_2d, arr2_2d])
print(arr_2dCon)
Comment

NumPy Concatenate Arrays

# Example 1: Use concatenate() to join two arrays
con = np.concatenate((arr, arr1))
print(con)

# Example 2: Use concatenate() with axis
con = np.concatenate((arr, arr1), axis=1)
print(con)

# Example 3: Use np.stack() function to Join Arrays
con = np.stack((arr, arr1), axis=1)
print(con)

# Example 4: Use np.hstack() function
con = np.hstack((arr, arr1))
print(con)

# Example 5: Use np.vstack() function 
con = np.vstack((arr, arr1))
print(con)

# Example 6: Use np.dstack() function to Stacking Along Height (depth)
con = np.dstack((arr, arr1))
print(con)
Comment

PREVIOUS NEXT
Code Example
Python :: change directory in python os 
Python :: python requests get title 
Python :: user agents list 
Python :: conda python 3.8 
Python :: change type of array python 
Python :: pandas select by column value 
Python :: pandas set a column as index 
Python :: remove r and n from string python 
Python :: clear console python 
Python :: how to get latitude and longitude from address in python 
Python :: python reference script directory 
Python :: convert epoch to date time in python 
Python :: python copy file 
Python :: pandas drop empty columns 
Python :: find the closest position by time list python 
Python :: install pandas in python mac 
Python :: python pi value 
Python :: find all text in site python 
Python :: python opencv write text on image 
Python :: bmi python 
Python :: python open new chrome tab 
Python :: f-string ponto decimal python 
Python :: python tts 
Python :: django how to set a navbar active 
Python :: import NoSuchKey in boto3 
Python :: python install module from script 
Python :: find duplicated rows with respect to multiple columns pandas 
Python :: how to plot 2 decimal values in axis python 
Python :: plotly plot size 
Python :: selenium page down key python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =