NumPy 中的 stack函数

首页 / Numpy入门教程 / NumPy 中的 stack函数

此函数沿新轴连接数组序列。自NumPy 1.10.0版本以来已添加此功能。需要提供以下参数。

注意-此功能在版本1.10.0 及更高版本中可用。

numpy.stack(arrays, axis)

哪里,

Sr.No. Parameter & 描述
1

arrays

相同维度的数组序列

无涯教程网

2

axis

输入数组沿其堆叠的输出数组中的轴

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)

它应该产生以下输出-

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]]]

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

零基础学Python -〔尹会生〕

技术管理实战36讲 -〔刘建国〕

从0开始学大数据 -〔李智慧〕

Linux实战技能100讲 -〔尹会生〕

说透中台 -〔王健〕

NLP实战高手课 -〔王然〕

Django快速开发实战 -〔吕召刚〕

中间件核心技术与实战 -〔丁威〕

零基础GPT应用入门课 -〔林健(键盘)〕

好记忆不如烂笔头。留下您的足迹吧 :)