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函数的更多相关文章

  1. np.repeat 与 np.tile

    1.Numpy的 tile() 函数,就是将原矩阵横向.纵向地复制.tile 是瓷砖的意思,顾名思义,这个函数就是把数组像瓷砖一样铺展开来. 举个例子,原矩阵: import numpy as np ...

  2. np.tile(), np.repeat() 和 tf.tile()

    以上三个函数,主要区别在于能够拓展维度上和重复方式: np.tile() 能够拓展维度,并且整体重复: a = np.array([0,1,2]) np.tile(a,(2,2)) # out # a ...

  3. numpy 辨异(四)—— np.repeat 与 np.tile

    >> import numpy as np >> help(np.repeat) >> help(np.tile) 二者执行的是均是复制操作: np.repeat: ...

  4. np.argsort函数

    np.argsort函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me numpy.argsort(a, axis=-1, kind='quicksort', order=None) 功能: ...

  5. np.diff函数

    np.diff函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me 数组中a[n]-a[n-1] import numpy as np a=np.array([1, 6, 7, 8, 12]) ...

  6. concat函数,concat_ws函数,group_concat函数,repeat()函数

    MySQL中concat函数使用方法:CONCAT(str1,str2,-) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...

  7. np.repeat()

    np.repeat()用于将numpy数组重复. numpy.repeat(a, repeats, axis=None); 参数: axis=0,沿着y轴复制,实际上增加了行数axis=1,沿着x轴复 ...

  8. 理解np.nonzero()函数

    举三个例子,就能清楚的看到 np.nonzero() 这个函数返回值的意义 一. #例1 一维数组 import numpy as np a = [0,1,2,0,3,0] b = np.nonzer ...

  9. Py之np.concatenate函数【转载】

    转自:https://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html 1.nupmy.concatenate函数 ...

随机推荐

  1. 【每日scrum】第一次冲刺day2

    和小伙伴一起找地图 ,学习了mapinfo地图格式的基本知识,数据和图像分开存储

  2. 软工1816 · 作业(十二)Beta答辩总结

    组长博客 宣传视频 github团队项目仓库 本组成员 队员姓名与学号 124 王彬(组长) 206 赵畅 215 胡展瑞 320 李恒达 131 佘岳昕 431 王源 206 陈文垚 209 陈志炜 ...

  3. mysql非安装包安装教程

    设置mysql的环境变量 本人设置安装的路径是:E:\WebApplication\webMySQL\mysql-5.7.13-winx64 我的电脑 ---> 高级系统配置 ---> 环 ...

  4. mysql 性能分析及explain用法

    转载自http://blog.sina.com.cn/s/blog_4586764e0100o9s1.html 使用explain语句去查看分析结果 如   explain select * from ...

  5. 深入理解JAVA集合系列三:HashMap的死循环解读

    由于在公司项目中偶尔会遇到HashMap死循环造成CPU100%,重启后问题消失,隔一段时间又会反复出现.今天在这里来仔细剖析下多线程情况下HashMap所带来的问题: 1.多线程put操作后,get ...

  6. NET Core 部署到 Windows服务

    https://www.cnblogs.com/linezero/p/5159927.html https://www.cnblogs.com/emrys5/p/nssm-netcore.html h ...

  7. LeetCode题解:(114) Flatten Binary Tree to Linked List

    题目说明 Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 ...

  8. syntax error:unexpected end of file

    将window上编辑的xxy1.sh脚本上传到linux上,并执行的时候提示 xxy1.sh: line 17: syntax error: unexpected end of file 但是通过ca ...

  9. [转帖] SQLNET.ORA的处理.

    被一个客户端连接远程数据库阻塞超时的问题困扰了好久,最后终于找到了答案  https://blog.csdn.net/herobox/article/details/16985097   Oracle ...

  10. 解决多进程中APScheduler重复运行的问题

    转自:http://blog.csdn.net/raptor/article/details/69218271 问题 在一个Python web应用中需要定时执行一些任务,所以用了APSchedule ...