Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 vstack Function Example with 2d array

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

import numpy as np

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

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

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

Python NumPy hstack Function Example with 2d array

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

import numpy as np

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

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

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

Python NumPy column_stack Function Example with 2d array

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

import numpy as np

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

in_arr2 = np.array([[5, 7, 9], [-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 2d array

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

import numpy as np

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

in_arr2 = np.array([[5, 7, 9], [-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 :: how to mention a role discord.py 
Python :: python type hints list of class 
Python :: graph implementation in python 
Python :: split a pd dataframe 
Python :: requesting with aiohttp 
Python :: python observer pattern 
Python :: python if string has spaces 
Python :: |= operator python 
Python :: python in kali linux 
Python :: how to create copy of all objects in list python 
:: python looping over a list 
Python :: SciPy Spatial Data 
Python :: random seed python 
Python :: how to define a functio in python 
Python :: keras name model 
Python :: read one column pandas 
Python :: python random.sample 
Python :: Split a list based on a condition 
Python :: python dataframe show row 
Python :: how to delete a column in pandas dataframe 
Python :: flask orm update query 
Python :: print torch model python 
Python :: deleting a tuple in python 
Python :: mixpanel export api 
Python :: insert into string python 
Python :: np logical not 
Python :: destory image in pygame 
Python :: how to create fastapi 
Python :: pandas print groupby 
Python :: pandas filter rows by column value regex 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =