将多个数组合并成一个,或将一个数组分裂成多个。

数组拼接
concatenate([a1, a2, ...], axis=0, out=None) #默认沿axis = 0轴拼接,也可设置沿axis = 1轴拼接
hstack([a1, a2, ...]) #默认沿axis = 0轴拼接
vstack([a1, a2, ...]) #默认沿axis = 1轴拼接
In [41]: grid = np.array([[1,2,3],[4,5,6]])

#沿0轴合并
In [42]: np.concatenate([grid,grid])
Out[42]:
array([[1, 2, 3],
[4, 5, 6],
[1, 2, 3],
[4, 5, 6]]) In [45]: np.vstack([grid,grid])
Out[45]:
array([[1, 2, 3],
[4, 5, 6],
[1, 2, 3],
[4, 5, 6]]) #沿1轴合并
In [43]: np.concatenate([grid,grid],axis=1)
Out[43]:
array([[1, 2, 3, 1, 2, 3],
[4, 5, 6, 4, 5, 6]]) In [44]: np.hstack([grid,grid])
Out[44]:
array([[1, 2, 3, 1, 2, 3],
[4, 5, 6, 4, 5, 6]])
数组分裂
np.split(ary, indices_or_sections, axis=0) #默认沿axis = 0轴分割,也可设置沿axis = 1轴分割
hsplit([a1, a2, ...]) #默认沿axis = 0轴分割
vplit([a1, a2, ...]) #默认沿axis = 1轴分割
In [54]: grid = np.arange(16).reshape((4,4))
In [55]: grid
Out[55]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]]) #沿0轴分割
In [56]: upper,lower = np.split(grid,[3])
In [57]: upper
Out[57]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]]) In [58]: lower
Out[58]: array([[12, 13, 14, 15]]) In [59]: upper,lower = np.vsplit(grid,[3])
In [60]: upper
Out[60]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]]) In [61]: lower
Out[61]: array([[12, 13, 14, 15]]) #沿1轴分割
In [62]: left,right = np.split(grid,[2],axis=1)
In [63]: left
Out[63]:
array([[ 0, 1],
[ 4, 5],
[ 8, 9],
[12, 13]]) In [64]: right
Out[64]:
array([[ 2, 3],
[ 6, 7],
[10, 11],
[14, 15]]) In [65]: left,right = np.hsplit(grid,[2])
In [66]: left
Out[66]:
array([[ 0, 1],
[ 4, 5],
[ 8, 9],
[12, 13]]) In [67]: right
Out[67]:
array([[ 2, 3],
[ 6, 7],
[10, 11],
[14, 15]])

Numpy数组拼接和分裂的更多相关文章

  1. python numpy 数组拼接

    我就写一下我遇到的,更多具体的请看Python之Numpy数组拼接,组合,连接 >>> aarray([0, 1, 2],       [3, 4, 5],       [6, 7, ...

  2. numpy数组 拼接

    转载自:https://blog.csdn.net/zyl1042635242/article/details/43162031 数组拼接方法一 首先将数组转成列表,然后利用列表的拼接函数append ...

  3. 【Python】numpy 数组拼接、分割

    摘自https://docs.scipy.org 1.The Basics 1.1 numpy 数组基础 NumPy’s array class is called ndarray. ndarray. ...

  4. numpy——>数组拼接np.concatenate

    语法:np.concatenate((a1, a2, ...), axis=0) 1.默认是 axis = 0,也就是说对0轴(行方向)的数组对象,进行其垂直方向(axis=1)的拼接(即数据整行整行 ...

  5. Python之Numpy数组拼接,组合,连接

    转自:https://www.douban.com/note/518335786/?type=like ============改变数组的维度==================已知reshape函数 ...

  6. Numpy数组基本操作(数组索引,数组切片以及数组的形状,数组的拼接与分裂)

    一:数组的属性 每个数组都有它的属性,可分为:ndim(数组的维度),shape(数组每个维度的大小),size(数组的总大小),dtype(数组数据的类型) 二:数组索引 和python列表一样,N ...

  7. numpy库数组拼接np.concatenate的用法

    concatenate功能:数组拼接 函数定义:numpy.concatenate((a1, a2, ...), axis=0, out=None)

  8. NumPy - 数组(定义,拼接)

    NumPy 教程(数组) set_printoptions(threshold='nan') NumPy的数组中比较重要ndarray对象属性有: ndarray.ndim:数组的维数(即数组轴的个数 ...

  9. 1.2 NumPy数组基础

    目录 第一章 numpy入门 1.2 numpy数组基础 1.2.1 数组的属性 1.2.2 数组的索引:获取单个元素 1.2.3 数组切片:获取子数组 1.2.4 数组的变形 1.2.5 数组的拼接 ...

  10. numpy数组的操作

    numpy - 介绍.基本数据类型.多维数组ndarray及其内建函数 http://blog.csdn.net/pipisorry/article/details/22107553 http://w ...

随机推荐

  1. 网络安全-Linux常用命令

    安装上传下载的软件包 yum install lrzsz -y 下载:linux-->windows sz -y /etc/hosts 上传:windows-->linux rz -y 系 ...

  2. Html飞机大战(十三): 暂停状态编辑

    好家伙,本篇介绍如何添加暂停状态 按照惯例我们依旧先分析思路 什么时候游戏应该暂停? 当我的鼠标不在游戏画面内了,我们就可以直接暂停了 在当我的鼠标回来以后,我们继续进行游戏 所以我们可以监听一个鼠标 ...

  3. FROM_UNIXTIME函数格式化时间戳日期类型

    select FROM_UNIXTIME(bce.daysec_time/1000,'%Y-%m-%d %h:%i:%s') ,bce.* from biz_cvent bce where bce.d ...

  4. 【Azure 应用服务】Azure Function App Linux环境下的Python Function,安装 psycopg2 模块错误

    问题描述 在Azure中创建Function App(函数应用), 用以运行Python代码(Python Version 3.7). 通过VS Code创建一个HttpTrigger的Functio ...

  5. curl比较有用的参数

     精选参数: --include // -i curl的输出中包含http头信息--verbose // 比-i更加丰富,>表示请求的信息, <表示curl接收的信息 *表示curl额外提 ...

  6. opencv库图像基础2-python

    opencv库图像基础2-python 图像的简单变换 先导入库 import cv2 import matplotlib.pyplot as plt import numpy as np 1.图像的 ...

  7. RocketMQ(3) 根据消息key查询功能的实现: indexFile

    三: indexFile 除了通过通常的指定Topic进行消息消费外,RocketMQ还提供了根据key进行消息查询的功能. 该查询是通过store目录中的index子目录中的indexFile进行索 ...

  8. vscode sftp 代码同步到服务器

    然后执行 ctrl+shift+p ,搜索 SFTP:Config 回车后,会生成一个".vscode/sftp.json",这个就是配置文件 参考:VsCode SFTP插件详细 ...

  9. AMD Intel CPU 对比图

  10. Python中的join()函数的用法实例分析

    一.join()函数 语法:  'sep'.join(seq) 参数说明sep:分隔符.可以为空seq:要连接的元素序列.字符串.元组.字典上面的语法即:以sep作为分隔符,将seq所有的元素合并成一 ...