np.repeat函数
np.repeat用法
觉得有用的话,欢迎一起讨论相互学习~Follow Me
np.repeat用于将numpy数组重复
一维数组重复三次
import numpy as np
# 随机生成[0,5)之间的数,形状为(1,4),将此数组重复3次
pop = np.random.randint(0, 5, size=(1, 4)).repeat(3, axis=0)
print("pop\n",pop)
# pop
# [[0 0 3 1]
# [0 0 3 1]
# [0 0 3 1]]
二维数组在第一维和第二维分别重复三次
pop_reshape=pop.reshape(2,6)
pop_reshape_repeataxis0=pop_reshape.repeat(3,axis=0)
pop_reshape_repeataxis1=pop_reshape.repeat(3,axis=1)
print("pop_reshape\n",pop_reshape)
print("pop_reshape_repeataxis0\n",pop_reshape_repeataxis0)
print("pop_reshape_repeataxis1\n",pop_reshape_repeataxis1)
# pop_reshape
# [[0 0 3 1 0 0]
# [3 1 0 0 3 1]]
# pop_reshape_repeataxis0
# [[0 0 3 1 0 0]
# [0 0 3 1 0 0]
# [0 0 3 1 0 0]
# [3 1 0 0 3 1]
# [3 1 0 0 3 1]
# [3 1 0 0 3 1]]
# pop_reshape_repeataxis1
# [[0 0 0 0 0 0 3 3 3 1 1 1 0 0 0 0 0 0]
# [3 3 3 1 1 1 0 0 0 0 0 0 3 3 3 1 1 1]]
np.repeat函数的更多相关文章
- np.repeat 与 np.tile
1.Numpy的 tile() 函数,就是将原矩阵横向.纵向地复制.tile 是瓷砖的意思,顾名思义,这个函数就是把数组像瓷砖一样铺展开来. 举个例子,原矩阵: import numpy as np ...
- np.tile(), np.repeat() 和 tf.tile()
以上三个函数,主要区别在于能够拓展维度上和重复方式: np.tile() 能够拓展维度,并且整体重复: a = np.array([0,1,2]) np.tile(a,(2,2)) # out # a ...
- numpy 辨异(四)—— np.repeat 与 np.tile
>> import numpy as np >> help(np.repeat) >> help(np.tile) 二者执行的是均是复制操作: np.repeat: ...
- np.argsort函数
np.argsort函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me numpy.argsort(a, axis=-1, kind='quicksort', order=None) 功能: ...
- np.diff函数
np.diff函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me 数组中a[n]-a[n-1] import numpy as np a=np.array([1, 6, 7, 8, 12]) ...
- concat函数,concat_ws函数,group_concat函数,repeat()函数
MySQL中concat函数使用方法:CONCAT(str1,str2,-) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...
- np.repeat()
np.repeat()用于将numpy数组重复. numpy.repeat(a, repeats, axis=None); 参数: axis=0,沿着y轴复制,实际上增加了行数axis=1,沿着x轴复 ...
- 理解np.nonzero()函数
举三个例子,就能清楚的看到 np.nonzero() 这个函数返回值的意义 一. #例1 一维数组 import numpy as np a = [0,1,2,0,3,0] b = np.nonzer ...
- Py之np.concatenate函数【转载】
转自:https://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html 1.nupmy.concatenate函数 ...
随机推荐
- 《JavaScript》split和join
首先了解split和join两个函数 split 根据条件截断字符串,返回数组 //str.split(option,length) 字符串转数组 //option:表示分割依据 //length:用 ...
- linux下创建virtualenv时指定python版本
virtualenv是python开发中一个重要的工具,它可以帮助我们创建一个干净的python解释环境,创建虚拟环境时,这个虚拟环境的python版本往往是系统默认的2.x版本.别急,我们只需要一条 ...
- github基础操作
1.最简单实用的操作 更新远程仓库 git status git add . git commit -m "add" git push #git push -u origin ma ...
- Leetcode题库——3.无重复字符的最长子串
@author: ZZQ @software: PyCharm @file: lengthOfLongestSubstring.py @time: 2018/9/18 20:35 要求:给定一个字符串 ...
- 树莓派与Arduino Leonardo使用NRF24L01无线模块通信之基于RF24库 (二) 发送自定义数据
在我的项目里,树莓派主要作为中心节点,用于接收数据,Arduino作为子节点,用于发送数据,考虑到以后会有很多子节点,但又不至于使得代码过于繁琐,因此所有的传输数据添加一个头部编号用于区分不同节点. ...
- Centos7 虚拟机复制后网卡问题 Job for network.service failed
在运行“/etc/init.d/network restart”命令时,出现错误“Job for network.service failed. See 'systemctl status netwo ...
- ASP.NET MVC 4.0 参考源码索引
http://www.projky.com/asp.netmvc/4.0/Microsoft/AspNet/Mvc/Facebook/FacebookAppSettingKeys.cs.htmlhtt ...
- Mongodb 分片操作 介绍
为什么需要分片操作?由于数据量太大,使得CPU,内存,磁盘I/O等压力过大.当MongoDB存储海量的数据时,一台机器可能不足以存储数据,也可能不足以提供可接受的读写吞吐量.这时,我们就可以通过在多台 ...
- LeetCode题解:(139) Word Break
题目说明 Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, dete ...
- override toString() function for TreeNode to output OJ's Binary Tree Serialization
class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } @Override publ ...