当前位置:网站首页>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
边栏推荐
- BLDC double closed loop (speed PI + current PI) Simulink simulation model
- B blocks of the 46th ICPC Asian regional competition (Kunming)
- Guangcheng cloud service can fill in a daily report regularly every day
- If MySQL / SQL server judges that the table or temporary table exists, it will be deleted
- The usage of case when and select case when is very easy to use
- Modify the content of MySQL + PHP drop-down box
- The difference between encodeuri and encodeuricomponent
- Rhcsa second day operation
- Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
- Opencv fills the rectangle with a transparent color
猜你喜欢
Error installing Mongo service 'mongodb server' on win10 failed to start
leangoo脑图-共享式多人协作思维导图工具分享
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
Day 3 of learning rhcsa
机器学习(周志华) 第十四章概率图模型
The input of El input input box is invalid, and error in data(): "referenceerror: El is not defined“
Encapsulate components such as pull-down menu based on ele
Liunx foundation - zabbix5 0 monitoring system installation and deployment
Sonic cloud real machine tutorial
Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
随机推荐
win查看端口占用 命令行
BLDC double closed loop (speed PI + current PI) Simulink simulation model
Résumé du gestionnaire de projet du système d'information Chapitre VI gestion des ressources humaines du projet
The shell monitors the depth of the IBM MQ queue and scans it three times in 10s. When the depth value exceeds 5 for more than two times, the queue name and depth value are output.
基于ele封装下拉菜单等组件
Looking for a job, writing a resume to an interview, this set of information is enough!
Shell script learning notes -- shell operation on files sed
字符串去掉空格问题
windows MySQL8 zip安装
Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
《信息系统项目管理师总结》第六章 项目人力资源管理
Shell learning notes -- shell processing of output stream awk
LeetCode 1450 - 1453
Encapsulate components such as pull-down menu based on ele
Encapsulation of ele table
Shell script learning notes - regular expressions
Rhcsa day 3 operation
Chapter VII project communication management of information system project manager summary
学习正则表达式选项、断言
【Hcip】OSPF常用的6种LSA详解