码迷,mamicode.com
首页 > 其他好文 > 详细

numpy.stack

时间:2021-02-20 12:05:27      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:rgba   移动   http   code   loading   arrays   参数   连接数   port   

numpy.stack 函数用于沿新轴连接数组序列,格式如下:

numpy.stack(arrays, axis)

参数说明:

  • arrays相同形状的数组序列
  • axis:返回数组中的轴,输入数组沿着它来堆叠

(深,高,宽)(0,1,2)经验证2x2数组插入axis轴后,原axis轴左移(超出原数组最高轴不用移动),维度加1。

 1 import numpy as np
 2 
 3 a=np.array([[1,2],[3,4]])
 4 b=np.array([[5,6],[7,8]])
 5 print(a)
 6 print(b)
 7 print(--------------------------------)
 8 c=np.stack((a,b),axis=0)
 9 print(c)
10 print(--------------------------------)
11 c=np.stack((a,b),axis=1)
12 print(c)
13 print(--------------------------------)
14 c=np.stack((a,b),axis=2)
15 print(c)

输出:

[[1 2]
 [3 4]]
[[5 6]
 [7 8]]
--------------------------------
[[[1 2]
  [3 4]]

 [[5 6]
  [7 8]]]
--------------------------------
[[[1 2]
  [5 6]]

 [[3 4]
  [7 8]]]
--------------------------------
[[[1 5]
  [2 6]]

 [[3 7]
  [4 8]]]

技术图片

numpy.stack

标签:rgba   移动   http   code   loading   arrays   参数   连接数   port   

原文地址:https://www.cnblogs.com/casperll/p/14415559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!