- NumPy Tutorial
- NumPy - Home
- NumPy - Introduction
- NumPy - Environment
- NumPy - Ndarray Object
- NumPy - Data Types
- NumPy - Array Attributes
- NumPy - Array Creation Routines
- NumPy - Array from Existing Data
- Array From Numerical Ranges
- NumPy - Indexing & Slicing
- NumPy - Advanced Indexing
- NumPy - Broadcasting
- NumPy - Iterating Over Array
- NumPy - Array Manipulation
- NumPy - Binary Operators
- NumPy - String Functions
- NumPy - Mathematical Functions
- NumPy - Arithmetic Operations
- NumPy - Statistical Functions
- Sort, Search & Counting Functions
- NumPy - Byte Swapping
- NumPy - Copies & Views
- NumPy - Matrix Library
- NumPy - Linear Algebra
- NumPy - Matplotlib
- NumPy - Histogram Using Matplotlib
- NumPy - I/O with NumPy
- NumPy Useful Resources
- NumPy Compiler
- NumPy - Quick Guide
- NumPy - Useful Resources
- NumPy - Discussion
numpy.stack
This function joins the sequence of arrays along a new axis. This function has been added since NumPy version 1.10.0. Following parameters need to be provided.
Note − This function is available in version 1.10.0 onwards.
numpy.stack(arrays, axis)
Where,
Sr.No. | Parameter & Description |
---|---|
1 | arrays Sequence of arrays of the same shape |
2 | axis Axis in the resultant array along which the input arrays are stacked |
Example
import numpy as np a = np.array([[1,2],[3,4]]) print 'First Array:' print a print '\n' b = np.array([[5,6],[7,8]]) print 'Second Array:' print b print '\n' print 'Stack the two arrays along axis 0:' print np.stack((a,b),0) print '\n' print 'Stack the two arrays along axis 1:' print np.stack((a,b),1)
It should produce the following output −
First array: [[1 2] [3 4]] Second array: [[5 6] [7 8]] Stack the two arrays along axis 0: [[[1 2] [3 4]] [[5 6] [7 8]]] Stack the two arrays along axis 1: [[[1 2] [5 6]] [[3 4] [7 8]]]
numpy_array_manipulation.htm
Advertisements
To Continue Learning Please Login
Login with Google