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 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 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

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 :: django on-delete options 
Python :: how to kill python program 
Python :: objects list 
Python :: verbose field names 
Python :: How can I Duplicate 1 Dimensional array 
Python :: Pandas DataFrame 2 
Python :: https://www.geeksforgeeks.org/matplotlib-axes-axes-cla-in-python/ 
Python :: codeforces problem 580A 
Python :: Python __ge__ magic method 
Python :: pyqt log widget thread safe 
Python :: python service linux 
Python :: Program to illustrate the use of nested if statement Average in python Grade =80 and above A =70 and <80 B =60 and <70 C =50 and <60 D Otherwise 
Python :: NumPy packbits Syntax 
Python :: tikzplotlib set figure 
Python :: python override inherited method data model constructor 
Python :: complete dates pandas per group by 
Python :: Remove Brackets from List Using for loop 
Python :: text to speech free python 
Python :: XML to table form in Excel 
Python :: python simplenamespace to json 
Python :: selsearch 
Python :: python event emitter 
Python :: how to map url with usernames prefixed 
Python :: cyclic rotation python 
Python :: knn.score sklearn 
Python :: ring Using Self.Attribute and Self.Method 
Python :: Hiding and encrypting passwords in Python using advpass() module 
Python :: salamelecus 
Python :: what is primary key in python 
Python :: websocket communitation to another pc python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =