1、纵向分割

>>> import numpy as np
>>> A = np.arange(12).reshape((3, 4))
>>> print(A)
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]] >>> print(np.split(A, 2, axis=1))#纵向分割
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2, 3],
[ 6, 7],
[10, 11]])]

2、横向分割

>>> print(np.split(A, 3, axis=0))
[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8, 9, 10, 11]])] >>> print(np.split(A, 3, axis=1))#错误分割范例
#范例的Array只有4列,只能等量对分,因此输入以上程序代码后Python就会报错。

3、不等量分割

>>> print(np.array_split(A, 3, axis=1))
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2],
[ 6],
[10]]), array([[ 3],
[ 7],
[11]])]

4、其他分割方式

>>> print(np.vsplit(A, 3)) #等于 print(np.split(A, 3, axis=0))
[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8, 9, 10, 11]])]
>>> print(np.hsplit(A, 2)) #等于 print(np.split(A, 2, axis=1))
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2, 3],
[ 6, 7],
[10, 11]])]

Numpy array分割的更多相关文章

  1. numpy array分割-【老鱼学numpy】

    有合并,就有分割. 本节主要讲述如何通过numpy对数组进行横向/纵向分割. 横向/纵向分割数组 首先创建一个6行4列的数组,然后我们对此数组按照横向进行切割,分成3块,这样每块应该有2行,见例子: ...

  2. numpy array 分割

    import numpy as np A = np.array([1,1,1])[:,np.newaxis] B = np.array([2,2,2])[:,np.newaxis] #合并 C = n ...

  3. numpy.array 合并和分割

    # 导包 import numpy as np numpy.array 的合并 .concatenate() 一维数组 x = np.array([1, 2, 3]) # array([1, 2, 3 ...

  4. Python Numpy Array

    Numpy 是Python中数据科学中的核心组件,它给我们提供了多维度高性能数组对象. Arrays Numpy.array   dtype 变量 dtype变量,用来存放数据类型, 创建数组时可以同 ...

  5. python numpy array 的一些问题

    1 将list转换成array 如果list的嵌套数组是不规整的,如 a = [[1,2], [3,4,5]] 则a = numpy.array(a)之后 a的type是ndarray,但是a中得元素 ...

  6. numpy.array

    关于python中的二维数组,主要有list和numpy.array两种. 好吧,其实还有matrices,但它必须是2维的,而numpy arrays (ndarrays) 可以是多维的. 我们主要 ...

  7. gensim与numpy array 互转

    目的 将gensim输出的格式转化为numpy array格式,支持作为scikit-learn,tensorflow的输入 实施 使用nltk库的停用词和网上收集的资料整合成一份新的停用词表,用来过 ...

  8. 找出numpy array数组的最值及其索引

    在list列表中,max(list)可以得到list的最大值,list.index(max(list))可以得到最大值对应的索引 但在numpy中的array没有index方法,取而代之的是where ...

  9. 「Python」Convert map object to numpy array in python 3

    转自Stackoverflow.备忘用. Question In Python 2 I could do the following: import numpy as np f = lambda x: ...

随机推荐

  1. 单例模式 demo

    // 用单例模式实现自定义颜色类 public class MyColor { private static MyColor _redColor = null; public static MyCol ...

  2. spring boot 程序打jar包及运行

  3. Anaconda安装及配合pycharm使用

    首先到https://www.anaconda.com/download/下载合适的anaconda版本.如Windows 64bit. 下载了直接双击开始下载,一路同意下去,到选择安装的目录.这里选 ...

  4. vue路由传参

    console.log( _this.$route.params.id)接收参数 <div class="baoming"><router-link :to=&q ...

  5. js 获取 this 的属性 obj[0].getAttribute

    js  获取 this 的属性 obj[0].getAttribute

  6. Spring @ControllerAdvice @ExceptionHandler 全局处理异常

    对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service 层抛出运行时异常,Spring 事物管理器就会进行回滚. 如此一来, ...

  7. cdnbest的站点日志保存时间怎么设置

    站点的保存时间是以节点全局里的保存时间为准 站点的日志保存大小还不能设置

  8. SOA 是什么

    SOA 英文:Service-Oriented Architecture,面向服务的架构. 是一种面向通用集成服务的.松耦合的架构实现方式,是web时代服务发展的产物: 使用"分层" ...

  9. input type='number'时,maxlength属性无效

    <input type="number" oninput="if(value.length>11)value=value.slice(0,11)"  ...

  10. 第四章 栈与队列(c4)栈应用:中缀表达式求值