As a new learner of Numpy, it is very common to be confused by the form of array, braces nested in braces, such as ‘a= np.array[[[1],[2],[3]]]’ so that its shape cannot be precisely known by the users, although the shape can be fetched through ‘a.shape’, making users unable to perform multidimensional array correctly.

The method is as the following:(1)every array needs a most out brace.(2) Go inner, the number of paired brace is the element number of 0 axis, 1 axis, 2 axis etc.(3) The dimension number increased along with the going-inner, until the number element is reached, the sum of levels is the dimensional number.

For example:

>>> import numpy as np
>>> data=np.arange(4)
>>> data1=data.reshape((4,1))
>>> data2=data.reshape((1,4))
>>> data3=data.reshape((2,2))
>>> data4=data.reshape((1,2,2))
>>> data5=data.reshape((2,1,2))
>>> data6=data.reshape((2,2,1))
>>> data
array([0, 1, 2, 3])
>>> data1
array([[0],
[1],
[2],
[3]])
>>> data2
array([[0, 1, 2, 3]])
>>> data3
array([[0, 1],
[2, 3]])
>>> data4
array([[[0, 1],
[2, 3]]])
>>> data5
array([[[0, 1]], [[2, 3]]])
>>> data6
array([[[0],
[1]], [[2],
[3]]])

①data1's shape is (4,1),so firstly, the most out brace pair shall be set-->[ ], and then 0 axis is 4, meaning 4 pairs of brace inside -->[ [ ],[ ],[ ],[ ] ] ,finally, 1 axis is 1,and is the final dimension, meaning 1 number element shall be inside-->[ [0],[1],[2],[3]].

② data2's shape is (1,4), firstly-->[ ], then -->[ [ ] ], finally -->[ [ 0,1,2,3] ]

③ data3's shape is (2,2), firstly-->[ ] ,then--> [ [ ], [ ] ], finally-->[ [0,1], [2,3] ]

④data4' shape is (1,2,2), firstly-->[ ] ,then-->[ [ ] ], then--> [ [ [ ], [ ] ] ], finally--> [ [ [ 0,1], [2,3 ] ] ]

⑤data5's shape is (2,1,2),firstly--> [ ],then-->[ [ ],[ ] ], then-->[ [ [ ] ], [ [ ] ] ], finally --> [ [ [ 0,1],[ [ 2,3] ] ]

⑥data6's shape is (2,2,1),firstly-->[ ],then --> [ [ ] ,[ ] ],then-->[ [ [ ], [ ] ], [ [ ] , [ ] ] ],finally-->[ [ [ 0],[1] ], [ [2],[3] ] ]

A convenient way to recognize and handwrite multidimensional arrays in Numpy的更多相关文章

  1. Multidimensional Arrays

    Overview An array having more than two dimensions is called a multidimensional array in the MATLAB® ...

  2. [Java in NetBeans] Lesson 13. Multidimensional Arrays

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. Multidimensional Array: Array that has more than one dimension. ...

  3. How do I learn machine learning?

    https://www.quora.com/How-do-I-learn-machine-learning-1?redirected_qid=6578644   How Can I Learn X? ...

  4. TensorFlow良心入门教程

    All the matrials come from Machine Learning class in Polyu,HK and I reorganize them and add referenc ...

  5. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  6. [转]50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs

    http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/ 50 Shades of Go: Traps, Gotc ...

  7. What is the fastest way of (not) logging?

    原文地址:http://www.slf4j.org/faq.html#logging_performance SLF4J supports an advanced feature called par ...

  8. awk overview

    VARIABLES, RECORDS AND FIELDS AWK  variables are dynamic; they come into existence when they are fir ...

  9. Java Knowledge series 3

    JVM & Bytecode Abstract & Object Object in Java (1) 所有东西都是对象object.可将对象想象成一种新型变量:它保存着数据,但可要求 ...

随机推荐

  1. Kali Linux RPi0w Nexmon操作笔记

    Kali Linux RPi0w Nexmon镜像下载地址:https://www.offensive-security.com/kali-linux-arm-images/ 1.烧录系统 可参考:树 ...

  2. idea 编译maven

    参考:https://blog.csdn.net/yye894817571/article/details/71681891

  3. leetcode #980 不同路径||| (java)

    在二维网格 grid 上,有 4 种类型的方格: 1 表示起始方格.且只有一个起始方格.2 表示结束方格,且只有一个结束方格.0 表示我们可以走过的空方格.-1 表示我们无法跨越的障碍.返回在四个方向 ...

  4. Using Watch Mode

    官方文档地址:https://webpack.js.org/guides/development/#using-watch-mode You can instruct webpack to " ...

  5. Codeforces1303E. Erase Subsequences

    转换一下题意,就相当于问t能不能和s中2个不相同的子串相同,我们可以将t串拆成2个子串t1,t2,得到状态dp[i][j][k]=0/1,表示s判断到i位,t1判断到j位,t2判断到k位,0/1表示是 ...

  6. 如何使用gcc_clang进行C语言的编译_编译的流程是什么?

    编译命令 gcc/clang -g -O2 -o -c test test.c -I... -L... -l -g : 输出文件中的调试信息 -O : 对输出文件做出指令优化,默认是O1, O2优化更 ...

  7. 138、Java内部类之访问内部类的私有属性

    01.代码如下: package TIANPAN; class Outer { // 外部类 private String msg = "Hello World !"; class ...

  8. Acwing272 最长公共上升子序列

    题目大意:给定两个大小为n的数组,让你找出最长公共上升子序列的长度. 分析:这是一个比较好的dp题,LIS和LCS两大经典线性dp问题相结合,简称LCIS. 代码(O(n*n*n)写法): #incl ...

  9. 第2节 storm路由器项目开发:8 - 9、集群监控软件ganglia的安装和使用

    Ganglia监控Hadoop集群的安装部署 详情请参见 http://boendev.iteye.com/blog/1750615 一. 安装环境 CentOS6.5x86_64 安装gmetad的 ...

  10. 伪奢侈品iPhone大降价,肉搏国产手机胜算几何?

    据国外媒体报道,苹果在中国降低iPhone价格的策略已收到明显的效果,自从1月11日正式调整价格以来,iPhone在苏宁电器平台上的销量飙升83%,而天猫上的销量也增长了76%,其中最受欢迎的机型是i ...