NumPy 中的 stack函数

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

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

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

链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-stack.html

来源:LearnFk无涯教程网

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

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

技术教程推荐

快速上手Kotlin开发 -〔张涛〕

程序员的数学基础课 -〔黄申〕

OpenResty从入门到实战 -〔温铭〕

Swift核心技术与实战 -〔张杰〕

跟月影学可视化 -〔月影〕

手把手带你搭建秒杀系统 -〔佘志东〕

现代C++20实战高手课 -〔卢誉声〕

B端产品经理入门课 -〔董小圣〕

结构执行力 -〔李忠秋〕

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