当前位置:网站首页>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
边栏推荐
- windows MySQL8 zip安装
- JZ22 链表中倒数最后k个结点
- Rhcsa day 1 operation
- 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.
- Configuring Apache Web services for servers such as Tianyi cloud
- 基于多态的职工管理系统源码与一些理解
- Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet
- Kubernetes - detailed explanation of pod
- 《信息系统项目管理师总结》第六章 项目人力资源管理
- Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
猜你喜欢

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

ROP Emporium x86_ 64 7 ~ 8 questions

It turns out that PID was born in the struggle between Lao wangtou and Lao sky

BLDC double closed loop (speed PI + current PI) Simulink simulation model
![How to use C language to realize [guessing numbers game]](/img/8c/052dcb0ce64ee1713bebb1340248e6.png)
How to use C language to realize [guessing numbers game]

Rhcsa day 1 operation

Sonic cloud real machine tutorial

Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)

Store consumption SMS notification template

Solve the problem that PowerShell mining occupies 100% of cpu7 in win7
随机推荐
基于Scrum进行创新和管理
JZ35 replication of complex linked list
Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl
The problem of removing spaces from strings
JS learning notes
Redis data server / database / cache (2022)
[hcip] detailed explanation of six LSAS commonly used by OSPF
If MySQL / SQL server judges that the table or temporary table exists, it will be deleted
The difference between encodeuri and encodeuricomponent
JS relearning
JS using the parameters of art template
基于多态的职工管理系统源码与一些理解
Rhcsa second day operation
LeetCode 1450 - 1453
Chapter VI project information management system summary
[unity3d] rolling barrage effect in live broadcasting room
ROP Emporium x86_64 7~8题
Day 4 of learning rhcsa
BLDC double closed loop (speed PI + current PI) Simulink simulation model
B blocks of the 46th ICPC Asian regional competition (Kunming)