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 row_stack Function Syntax 
Python :: Python NumPy split Function Example when index attribute given wrong 
Python :: advanced python code copy and paste 
Python :: percentile of a score python 
Python :: configure socketio static file python specific content type 
Python :: Python NumPy hsplit Function Syntax 
Python :: python increase a value every n rows 
Python :: maximaze window in tkinter 
Python :: Python __sub__ magic method 
Python :: django ejemplo de un formulario crud 
Python :: python mxs Classof 
Python :: how to split a string every 2 characters python 
Python :: NumPy invert Code When the input is a number 
Python :: django view - APIView (urls.py config) 
Python :: using .get() for deep dictionary 
Python :: if not isinstance multiple values 
Python :: Use PIP from inside script 
Python :: django hash password Argon 
Python :: python tkinter.ttk combobox down event on mouseclick 
Python :: print(i) 
Python :: python readlines  
Python :: how do i add two matrix and store it in a list in python 
Python :: Dynamic use of templates in Jinja2 
Python :: get command line variables python 
Python :: patterns and matcher nfa python code 
Python :: ring load the odbclib.ring library 
Python :: ring execute the program line by line 
Python :: importing cosine from scipy 
Python :: how to ge squrre root symobl as string inpython 
Python :: custom 3d image generator for segmentation 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =