Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python NumPy stack Function Example with 1d array

# welcome to softhunt.net
# Python program explaining
# stack() function

import numpy as np

# input array
in_arr1 = np.array([1, 3, 5] )
print ("1st Input array : 
", in_arr1)

in_arr2 = np.array([2, 4, 6] )
print ("2nd Input array : 
", in_arr2)

# Stacking the two arrays along axis 0
out_arr1 = np.stack((in_arr1, in_arr2), axis = 0)
print ("Output stacked array along axis 0:
 ", out_arr1)

# Stacking the two arrays along axis 1
out_arr2 = np.stack((in_arr1, in_arr2), axis = 1)
print ("Output stacked array along axis 1:
 ", out_arr2)
Comment

Python NumPy stack Function Example with 2d array

# welcome to softhunt.net
# Python program explaining
# stack() function

import numpy as np

# input array
in_arr1 = np.array([[1, 3, 5], [-1, -3, -5]] )
print ("1st Input array : 
", in_arr1)

in_arr2 = np.array([[2, 4, 6], [-2, -4, -6]] )
print ("2nd Input array : 
", in_arr2)

# Stacking the two arrays along axis 0
out_arr1 = np.stack((in_arr1, in_arr2), axis = 0)
print ("Output stacked array along axis 0:
 ", out_arr1)

# Stacking the two arrays along axis 1
out_arr2 = np.stack((in_arr1, in_arr2), axis = 1)
print ("Output stacked array along axis 1:
 ", out_arr2)

# Stacking the two arrays along last axis
out_arr3 = np.stack((in_arr1, in_arr2), axis = -1)
print ("Output stacked array along last axis :
 ", out_arr3)
Comment

Python NumPy hstack Function Example with 1d array

# welcome to softhunt.net
# Python program explaining
# hstack() function

import numpy as np

# input array
in_arr1 = np.array([0, 1, 3] )
print ("1st Input array : 
", in_arr1)

in_arr2 = np.array([5, 7, 9] )
print ("2nd Input array : 
", in_arr2)

# Stacking the two arrays horizontally
out_arr = np.hstack((in_arr1, in_arr2))
print ("Output horizontally stacked array:
 ", out_arr)
Comment

Python NumPy column_stack Function Example with 1d array

# welcome to softhunt.net
# Python program explaining
# column_stack() function

import numpy as np

# input array
in_arr1 = np.array((0, 1, 3,))
print ("1st Input array : 
", in_arr1)

in_arr2 = np.array((5, 7, 9))
print ("2nd Input array : 
", in_arr2)

# Stacking the two arrays
out_arr = np.column_stack((in_arr1, in_arr2))
print ("Output stacked array:
 ", out_arr)
Comment

Python NumPy row_stack Function Example with 1d array

# welcome to softhunt.net
# Python program explaining
# row_stack() function

import numpy as np

# input array
in_arr1 = np.array((0, 1, 3,))
print ("1st Input array : 
", in_arr1)

in_arr2 = np.array((5, 7, 9))
print ("2nd Input array : 
", in_arr2)

# Stacking the two arrays
out_arr = np.row_stack((in_arr1, in_arr2))
print ("Output stacked array:
 ", out_arr)
Comment

PREVIOUS NEXT
Code Example
Python :: Display shape of the DataFrame 
Python :: create folders in python overwright existing 
Python :: supress jupyter notebook output 
Python :: search mean in python using pandas 
Python :: looping over dictionary python 
Python :: how to sum numpy matrix diagonal 
Python :: binary search tree implementation in python 
Python :: python - extract min and max values per each column name 
Python :: recall at k calculate python 
Python :: how to find out the max and min date on the basis of property id in pandas 
Python :: get all commands discord.py 
Python :: how to get the top 100 frequent words on a python dataframe colummn 
Python :: python book 
Python :: python inspect 
Python :: stock market python 
Python :: get_or_create in django 
Python :: pickle dump example 
Python :: python pytest no coverage on failure 
Python :: python colored text in console 
Python :: python divide and round away operator 
Python :: authentication serializer drf 
Python :: pandas index append value 
Python :: generating datafraoms using specific row values 
Python :: pygame template 
Python :: pandas fill missing index values 
Python :: python convert float to whole part of number 
Python :: change every element of list python with map 
Python :: how to exit a loop in python 
Python :: assign multiple columns pandas 
Python :: count items in list python by loop 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =