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

PREVIOUS NEXT
Code Example
Python :: Python NumPy hstack Function Example with 2d array 
Python :: Python NumPy column_stack Function Example with 1d array 
Python :: django on-delete options 
Python :: how to change text in heatmap matplotlib 
Python :: python locateonscreen method 
Python :: Python NumPy tile Function Example Working with 1D array 
Python :: get method from plot 
Python :: torch mean of tensor 
Python :: Python __ne__ 
Python :: split() without argument 
Python :: NumPy bitwise_and Example When inputs are numbers 
Python :: track keyboard press pynput 
Python :: NumPy bitwise_or Code When inputs are Boolean 
Python :: python subprocess redirect a file 
Python :: qt list widget let editable 
Python :: fibo_itrativ 
Python :: get primary key in get_context_data 
Python :: pandas impute zero 
Python :: How to set a tkinter window to a constant size 
Python :: opencv2.3 
Python :: pandas groupby min get index 
Python :: sqlite basic 
Python :: sklearn encoding pipelin 
Python :: how to blend pixels in pygame 
Python :: containsDuplicate Set Solution 
Python :: ring print part of the content of a binary file 
Python :: ring Type Hints Library 
Python :: mehrzeiliges kommentar python 
Python :: import sys execute cmd 
Python :: How to play audio in background 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =