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:

  1. >>> import numpy as np
  2. >>> data=np.arange(4)
  3. >>> data1=data.reshape((4,1))
  4. >>> data2=data.reshape((1,4))
  5. >>> data3=data.reshape((2,2))
  6. >>> data4=data.reshape((1,2,2))
  7. >>> data5=data.reshape((2,1,2))
  8. >>> data6=data.reshape((2,2,1))
  9. >>> data
  10. array([0, 1, 2, 3])
  11. >>> data1
  12. array([[0],
  13. [1],
  14. [2],
  15. [3]])
  16. >>> data2
  17. array([[0, 1, 2, 3]])
  18. >>> data3
  19. array([[0, 1],
  20. [2, 3]])
  21. >>> data4
  22. array([[[0, 1],
  23. [2, 3]]])
  24. >>> data5
  25. array([[[0, 1]],
  26.  
  27. [[2, 3]]])
  28. >>> data6
  29. array([[[0],
  30. [1]],
  31.  
  32. [[2],
  33. [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. 吴裕雄--天生自然ORACLE数据库学习笔记:数据导出与导入

    create directory dump_dir as 'd:\dump'; grant read,write on directory dump_dir to scott; --在cmd下 exp ...

  2. linux面试经验

    互联网面试想必是每个学计算机的学生必不可少的环节,无论你的项目经验再多,你不准备基础知识,也还是无济于事.首先来说说关于工作的事情. 三年前,那时候我还是刚刚快要大四毕业的小鲜肉,那时候有个超大的招聘 ...

  3. LaTeX 使用笔记

    实现一个归类样式,如图: 代码: \left\{ \begin{aligned} 监督学习 \left\{ \begin{aligned} 回归 \\ 分类 \end{aligned} \right. ...

  4. IDEA中打war 包

    把war 放入tomcat 的 webapps 目录下,重启tomcat即可自动解压war包跑起来 (最好是,解压完成后,关闭tomcat,把war包拷贝出去,再启动,不然每次启动tomcat都会自动 ...

  5. ssh_crm项目

    1.代码 https://pan.baidu.com/s/1hudAhA8  密码:c7xu 2.总结 https://pan.baidu.com/s/1o9ArFf0 密码:hteu 3.资料 ht ...

  6. 带你了解后渗透工具Koadic

    前言: 在朋友的博客上看到推荐的一款工具Koadic,我接触了以后发现很不错这款工具的强大之处我觉得就是拿到shell后的各种模块功能,我就自己写出来发给大家看看吧. 首先把项目克隆到本地: 项目地址 ...

  7. java并发LockSupport

    java并发LockSupport LockSupport是阻塞和唤醒线程的重要类. park()方法使得当前线程阻塞 unpark(Thread thread)唤醒线程 例子 可以把注释取消再执行, ...

  8. Python学习第四课——基本数据类型一之int and str

    1.数字(int) - int() 方法 # 定义 a1=123 a2=456 #功能1:将字符串转换为数字 #例子1: a = " print(type(a)) # type()为查看类型 ...

  9. Numpy与List之间的转换

    说明:在做NLP的时候,经常需要查看当前数组数据的维度,也就是data.shape,而List是没有这个属性的,因此需要先将其转换成Numpy,以下为两者户想转换的方法 List转Numpy:nump ...

  10. Maven项目- Servlet的抽取和优化 java.lang.NoSuchMethodException 的解决方法

    优化servlet,减少servlet的数量,便于开发与维护.现在是一个功能一个Servlet,将其优化为一个模块一个Servlet,BaseServlet的抽取和优化,相当于在数据库中一张表对应一个 ...