NumPy 中的 append函数

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

此函数在输入数组的末尾添加值,输入数组的维度也必须匹配,否则将生成ValueError。

该函数采用以下参数。

numpy.append(arr, values, axis)
Sr.No. Parameter & 描述
1

arr

输入数组

2

values

要附加到arr。它的维度必须与arr相同

3

axis

沿其执行附加操作的轴。如果未给出,则将两个参数展平

import numpy as np 
a = np.array([[1,2,3],[4,5,6]]) 

print 'First array:' 
print a 
print '\n'  

print 'Append elements to array:' 
print np.append(a, [7,8,9]) 
print '\n'  

print 'Append elements along axis 0:' 
print np.append(a, [[7,8,9]],axis = 0) 
print '\n'  

print 'Append elements along axis 1:' 
print np.append(a, [[5,5,5],[7,8,9]],axis = 1)

其输出如下-

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

来源:LearnFk无涯教程网

First array:
[[1 2 3]
 [4 5 6]]

Append elements to array:
[1 2 3 4 5 6 7 8 9]

Append elements along axis 0:
[[1 2 3]
 [4 5 6]
 [7 8 9]]

Append elements along axis 1:
[[1 2 3 5 5 5]
 [4 5 6 7 8 9]]

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

技术教程推荐

如何设计一个秒杀系统 -〔许令波〕

从0开发一款iOS App -〔朱德权〕

TypeScript开发实战 -〔梁宵〕

安全攻防技能30讲 -〔何为舟〕

说透敏捷 -〔宋宁〕

OAuth 2.0实战课 -〔王新栋〕

乔新亮的CTO成长复盘 -〔乔新亮〕

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

Tony Bai · Go语言第一课 -〔Tony Bai〕

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