当前位置:网站首页>numpy重复数据
numpy重复数据
2022-06-09 20:45:00 【馋学习的身子】
numpy中主要使用tile函数和repeat函数实现数据重复
tile函数
tile函数的定义如下:
def tile(A, reps)
该函数主要有两个参数,参数A指定重复的数组,参数reps之订重复的次数。
注意:如果reps的长度为d,则最后重复后的数组的维度为max(d, A.ndim),即取d与A的维度的最大值。如果A.ndim < d,则通过添加新轴使A变为d维。例如对于shape为(3,)通过2维重复shape变为(1,3),通过3维的重复shape变为(1,1,3)。
例子:


repeat函数
函数的定义如下:
repeat(a, repeats, axis=None):
repeat函数主要有3个参数,参数a指定需要重复的数组元素,参数repeats指定重复次数,参数axis指定沿着哪个轴进行重复。
- axis=None,时候就会flatten当前矩阵,实际上就是变成了一个行向量
- axis=0,沿着y轴复制,实际上增加了行数
- axis=1,沿着x轴复制,实际上增加列数

>>> np.repeat(x, 3, axis=0)
array([[1, 2],
[1, 2],
[1, 2],
[3, 4],
[3, 4],
[3, 4]])
总结:
这两个函数的主要区别在于:tile函数是对数组进行重复操作,repeat函数是对数组中的每个元素进行重复操作。
边栏推荐
猜你喜欢

Bug in upgrading SD card / TF card of HMI serial interface screen

从源码解析flutter_redux 的精准局部刷新

瀏覽器無法打開百度,別的可以正常打開

Integer ordered array lookup -- traversal and half / bisection

【mysql】主从复制原理、搭建

HMI 创建工程生成字库的一个潜在bug

How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)

排序-快速排序

UTM to latitude and longitude

力扣84-柱状图中最大的矩形(单调栈)
随机推荐
快速了解服务器IO的实现
C#中委托的应用
力扣84-柱状图中最大的矩形(单调栈)
每日一题——leecode59( 螺旋矩阵 II)
浏览器无法打开百度,别的可以正常打开
Le navigateur ne peut pas ouvrir Baidu, d'autres peuvent être ouverts normalement
Mr. wuyaohui, the world pioneer of ordinary ternary logic mathematics, announced the scientific research achievements of all truth tables of ordinary ternary logic mathematics to the world (Wu's law)
C#中的泛型T的应用
Initial experience of transformation of vite lerna monorepo project
C reverse sort
Redis knowledge points
深夜小酌,50道经典SQL题,真香~
C#中的里氏替换原则
Soflu software robot: an automatic tool to assist enterprises in landing Devops
Detailed explanation of uboot
Cvpr2022 oral | cross view transformer for semantic segmentation of real-time map views
Modelarts storage proposal
开源一个 nodejs 防火墙小工具
SoFlu 软件机器人:辅助企业落地 DevOps 的自动化工具
ASP.NET手机终端进销存系统,源码分享