In [20]: b[0,:,1]
Out[20]: array([1, 5, 9])

In [21]: b[0,:,1]
Out[21]: array([1, 5, 9])

In [22]: b[0,:,-1]
Out[22]: array([ 3,  7, 11])

In [23]: b[0,::-1, -1]
Out[23]: array([11,  7,  3])

In [24]: b[0,::-2, -1]
Out[24]: array([11,  3])

In [25]: b[::-1]
Out[25]:
array([[[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]],

       [[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]]])

In [26]: b
Out[26]:
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],

       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]]])

In [27]: b.ravel()
Out[27]:
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 20, 21, 22, 23])

In [28]: b.flatten()
Out[28]:
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 20, 21, 22, 23])

In [29]: b.shape = (6,4)

In [30]: b
Out[30]:
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15],
       [16, 17, 18, 19],
       [20, 21, 22, 23]])

In [31]: b.transpose()
Out[31]:
array([[ 0,  4,  8, 12, 16, 20],
       [ 1,  5,  9, 13, 17, 21],
       [ 2,  6, 10, 14, 18, 22],
       [ 3,  7, 11, 15, 19, 23]])

In [32]: b.resize(2,12))
  File "<ipython-input-32-91b83b9b6cad>", line 1
    b.resize(2,12))
                  ^
SyntaxError: invalid syntax

In [33]: b.resize((2,12))

In [34]: b
Out[34]:
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]])

In [35]: a = arange(3).reshape(3,3)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-35-0863ec9f918e> in <module>()
----> 1 a = arange(3).reshape(3,3)

ValueError: cannot reshape array of size 3 into shape (3,3)

In [36]: a = arange(9).reshape(3,3)

In [37]: a
Out[37]:
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [38]: b = 2 * a

In [39]: b
Out[39]:
array([[ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16]])

In [40]: hstack((a,b))
Out[40]:
array([[ 0,  1,  2,  0,  2,  4],
       [ 3,  4,  5,  6,  8, 10],
       [ 6,  7,  8, 12, 14, 16]])

In [41]: concatenate((a,b), axis=1)
Out[41]:
array([[ 0,  1,  2,  0,  2,  4],
       [ 3,  4,  5,  6,  8, 10],
       [ 6,  7,  8, 12, 14, 16]])

In [42]: vstack((a,b))
Out[42]:
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16]])

In [43]: concatenate((a,b), axis=0)
Out[43]:
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16]])

In [44]: dstack((a,b))
Out[44]:
array([[[ 0,  0],
        [ 1,  2],
        [ 2,  4]],

       [[ 3,  6],
        [ 4,  8],
        [ 5, 10]],

       [[ 6, 12],
        [ 7, 14],
        [ 8, 16]]])

In [45]: a
Out[45]:
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [46]: hsplit(a, 3)
Out[46]:
[array([[0],
        [3],
        [6]]), array([[1],
        [4],
        [7]]), array([[2],
        [5],
        [8]])]

In [47]: hsplit(a, 3)
Out[47]:
[array([[0],
        [3],
        [6]]), array([[1],
        [4],
        [7]]), array([[2],
        [5],
        [8]])]

In [48]: split(a, 3, axis=1)
Out[48]:
[array([[0],
        [3],
        [6]]), array([[1],
        [4],
        [7]]), array([[2],
        [5],
        [8]])]

In [49]: vsplit(a, 3)
Out[49]: [array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]

In [50]: split(a, 3, axis=0)
Out[50]: [array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]

In [51]: c = arange(27).reshape(3, 3, 3)

In [52]: c
Out[52]:
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],

       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],

       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])

In [53]: dsplit(c,3)
Out[53]:
[array([[[ 0],
         [ 3],
         [ 6]],

        [[ 9],
         [12],
         [15]],

        [[18],
         [21],
         [24]]]), array([[[ 1],
         [ 4],
         [ 7]],

        [[10],
         [13],
         [16]],

        [[19],
         [22],
         [25]]]), array([[[ 2],
         [ 5],
         [ 8]],

        [[11],
         [14],
         [17]],

        [[20],
         [23],
         [26]]])]

In [54]: b
Out[54]:
array([[ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16]])

In [55]: b
Out[55]:
array([[ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16]])

In [56]: b.ndim
Out[56]: 2

In [57]: b.size
Out[57]: 9

In [58]: b.itemsize
Out[58]: 4

In [59]: b.nbytes
Out[59]: 36

In [60]: b.size * b.itemsize
Out[60]: 36

In [61]: b.resize(6,4)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-61-a30f6357ab78> in <module>()
----> 1 b.resize(6,4)

ValueError: cannot resize an array that references or is referenced
by another array in this way.  Use the resize function

In [62]: b.resize(6,6)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-62-5d4e603729e0> in <module>()
----> 1 b.resize(6,6)

ValueError: cannot resize an array that references or is referenced
by another array in this way.  Use the resize function

In [63]: b.resize()

In [64]: b
Out[64]:
array([[ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16]])

In [65]: b
Out[65]:
array([[ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16]])

In [66]: b.tolist()
Out[66]: [[0, 2, 4], [6, 8, 10], [12, 14, 16]]

In [67]:

numpy基础代码操练的更多相关文章

  1. 《利用python进行数据分析》读书笔记--第四章 numpy基础:数组和矢量计算

    http://www.cnblogs.com/batteryhp/p/5000104.html 第四章 Numpy基础:数组和矢量计算 第一部分:numpy的ndarray:一种多维数组对象 实话说, ...

  2. 利用Python进行数据分析——Numpy基础:数组和矢量计算

    利用Python进行数据分析--Numpy基础:数组和矢量计算 ndarry,一个具有矢量运算和复杂广播能力快速节省空间的多维数组 对整组数据进行快速运算的标准数学函数,无需for-loop 用于读写 ...

  3. 《利用Python进行数据分析·第2版》第四章 Numpy基础:数组和矢量计算

    <利用Python进行数据分析·第2版>第四章 Numpy基础:数组和矢量计算 numpy高效处理大数组的数据原因: numpy是在一个连续的内存块中存储数据,独立于其他python内置对 ...

  4. 利用python进行数据分析--numpy基础

    随书练习,第四章  NumPy基础:数组和矢量运算 # coding: utf-8 # In[1]: # 加注释的三个方法1.用一对"""括起来要注释的代码块. # 2. ...

  5. NumPy 基础知识·翻译完成

    原文:Numpy Essentials 协议:CC BY-NC-SA 4.0 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远. 在线阅读 ApacheCN 面试求职交流群 7241 ...

  6. 【学习笔记】 第04章 NumPy基础:数组和矢量计算

    前言 正式开始学习Numpy,参考用书是<用Python进行数据清洗>,计划本周五之前把本书读完,关键代码全部实现一遍 NumPy基础:数组和矢量计算 按照书中所示,要搞明白具体的性能差距 ...

  7. Mysql基础代码(不断完善中)

    Mysql基础代码,不断完善中~ /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限 ...

  8. 利用Python进行数据分析(5) NumPy基础: ndarray索引和切片

    概念理解 索引即通过一个无符号整数值获取数组里的值. 切片即对数组里某个片段的描述. 一维数组 一维数组的索引 一维数组的索引和Python列表的功能类似: 一维数组的切片 一维数组的切片语法格式为a ...

  9. numpy 基础操作

    Numpy 基础操作¶ 以numpy的基本数据例子来学习numpy基本数据处理方法 主要内容有: 创建数组 数组维度转换 数据选区和切片 数组数据计算 随机数 数据合并 数据统计计算 In [1]: ...

随机推荐

  1. 专题训练之数位DP

    推荐以下一篇博客:https://blog.csdn.net/wust_zzwh/article/details/52100392 1.(HDOJ2089)http://acm.hdu.edu.cn/ ...

  2. 洛谷P1637 三元上升子序列

    P1637 三元上升子序列 48通过 225提交 题目提供者该用户不存在 标签云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 为什么超时啊 a的数据比较 ...

  3. 我的emacs简易配置

    ;;------------语言环境字符集设置(utf-8)------------- (set-language-environment 'Chinese-GB) (set-keyboard-cod ...

  4. Nginx多个配置文件共用location配置

    一.应用情况 很多时候我们在一台服务器上部署了不止 一个项目,我们通过Nginx来代理,为了方便管理往往会将各个项目的配置分开写到不同的配置文件中,如: 在nginx.conf 文件中加上  incl ...

  5. svn工具的使用问题总结

    前言: 最近在开发的时候,由于需求太多,开发周期长短不一,从主线上切了多个分支(一般不在主线trunk上开发,万一线上出问题可及时修改代码上线),在部分功能上线后,想把代码同步到新的分支上去,最开始的 ...

  6. 1.java内存区域与内存溢出异常

    1.java运行时数据区如图所示: 2.每个区域的功能 (1)程序计数器(寄存器) 当前线程所执行的字节码的行号指示器 为了线程切换后能够恢复到正确的执行位置,因此每个线程拥有自己独立的程序计数器 如 ...

  7. bzoj 1901 Dynamic Rankings (树状数组套线段树)

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MB Description 给定一个含有n个数的序列a[1] ...

  8. 主席树 或者 离散化+分块 BZOJ 4636

    4636: 蒟蒻的数列 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 381  Solved: 177[Submit][Status][Discuss ...

  9. HDU 2157 How many ways?? 临接矩阵+快速幂

    Problem Description 春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, ...

  10. What are the advantages of different classification algorithms?

    What are the advantages of different classification algorithms? For instance, if we have large train ...