当前位置:网站首页>Numpy stack function
Numpy stack function
2022-04-23 02:56:00 【Live up to your youth】
The function prototype
numpy.stack(arrays, axis=0, out=None)
Function interpretation
Stack arrays with the same shape on the specified dimension
The usage function
A simple example of a two-dimensional array
>>> a = np.arange(9).reshape((3, 3))
>>> a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> b = np.arange(9, 18).reshape((3, 3))
>>> b
array([[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17]])
>>> c = np.arange(18, 27).reshape((3, 3))
>>> c
array([[18, 19, 20],
[21, 22, 23],
[24, 25, 26]])
# take a、b、c Three arrays on the axis axis=0 Stack on , Get a three-dimensional array
>>> d = np.stack((a, b, c), axis=0)
>>> d
array([[[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8]],
[[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17]],
[[18, 19, 20],
[21, 22, 23],
[24, 25, 26]]])
# take a、b、c Three arrays on the axis axis=1 Stack on , Also get a three-dimensional array
>>> e = np.stack((a, b, c), axis=1)
>>> e
array([[[ 0, 1, 2],
[ 9, 10, 11],
[18, 19, 20]],
[[ 3, 4, 5],
[12, 13, 14],
[21, 22, 23]],
[[ 6, 7, 8],
[15, 16, 17],
[24, 25, 26]]])
>>> f = np.stack((a, b, c), axis=2)
>>> f
array([[[ 0, 9, 18],
[ 1, 10, 19],
[ 2, 11, 20]],
[[ 3, 12, 21],
[ 4, 13, 22],
[ 5, 14, 23]],
[[ 6, 15, 24],
[ 7, 16, 25],
[ 8, 17, 26]]])
Let's take another example of a three-dimensional array
>>> a = np.zeros((2, 2, 2), dtype=int)
>>> a
array([[[0, 0],
[0, 0]],
[[0, 0],
[0, 0]]])
>>> b = np.ones((2, 2, 2), dtype=int)
>>> b
array([[[1, 1],
[1, 1]],
[[1, 1],
[1, 1]]])
>>> c = np.full((2, 2, 2), 2, dtype=int)
>>> c
array([[[2, 2],
[2, 2]],
[[2, 2],
[2, 2]]])
# In the shaft axis=0 Stack on
>>> d = np.stack((a, b, c), axis=0)
>>> d
array([[[[0, 0],
[0, 0]],
[[0, 0],
[0, 0]]],
[[[1, 1],
[1, 1]],
[[1, 1],
[1, 1]]],
[[[2, 2],
[2, 2]],
[[2, 2],
[2, 2]]]])
>>> d.shape
(3, 2, 2, 2)
>>> e = np.stack((a, b, c), axis=1)
>>> e
array([[[[0, 0],
[0, 0]],
[[1, 1],
[1, 1]],
[[2, 2],
[2, 2]]],
[[[0, 0],
[0, 0]],
[[1, 1],
[1, 1]],
[[2, 2],
[2, 2]]]])
>>> e.shape
(2, 3, 2, 2)
# In the shaft axis=2 Stack on
>>> f = np.stack((a, b, c), axis=2)
>>> f
array([[[[0, 0],
[1, 1],
[2, 2]],
[[0, 0],
[1, 1],
[2, 2]]],
[[[0, 0],
[1, 1],
[2, 2]],
[[0, 0],
[1, 1],
[2, 2]]]])
>>> f.shape
(2, 2, 3, 2)
# amount to g = np.stack((a, b, c), axis=-1)
>>> g = np.stack((a, b, c), axis=3)
>>> g
array([[[[0, 1, 2],
[0, 1, 2]],
[[0, 1, 2],
[0, 1, 2]]],
[[[0, 1, 2],
[0, 1, 2]],
[[0, 1, 2],
[0, 1, 2]]]])
>>> g.shape
(2, 2, 2, 3)
版权声明
本文为[Live up to your youth]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220657127458.html
边栏推荐
- C语言 171. 最近回文数
- php+mysql对下拉框搜索的内容修改
- BLDC double closed loop (speed PI + current PI) Simulink simulation model
- Day 4 of learning rhcsa
- @Usage and difference between mapper and @ repository
- Shell script learning -- practical case
- Rhcsa day 3 operation
- L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
- The input of El input input box is invalid, and error in data(): "referenceerror: El is not defined“
- VirtualBox virtual machine (Oracle VM)
猜你喜欢

Android high-level interview must ask: overall business and project architecture design and reconstruction

Intelligent agricultural management model

Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet

windows MySQL8 zip安装

解决win7 中powershell挖矿占用CPU100%

Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)

Day 3 of learning rhcsa

Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op

Fashion MNIST 数据集分类训练

php+mysql對下拉框搜索的內容修改
随机推荐
JS learning notes
Face longitude:
《信息系统项目管理师总结》第七章 项目沟通管理
Source code and some understanding of employee management system based on polymorphism
Step principle of logical regression in machine learning
Log4j knowledge point record
Shell script learning -- practical case
Leangoo brain map - shared multi person collaborative mind mapping tool
TypeScript(1)
Processes and threads
MySQL复杂查询使用临时表/with as(类似表变量)
The difference between encodeuri and encodeuricomponent
JS using the parameters of art template
Windows MySQL 8 zip installation
Publish to NPM?
The second day of learning rhcsa
基于Scrum进行创新和管理
Winsock programming interface experiment: Ping
BLDC double closed loop (speed PI + current PI) Simulink simulation model
Planning code ROS migration POMDP prediction planning (I)