A convenient way to recognize and handwrite multidimensional arrays in Numpy
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的更多相关文章
- Multidimensional Arrays
Overview An array having more than two dimensions is called a multidimensional array in the MATLAB® ...
- [Java in NetBeans] Lesson 13. Multidimensional Arrays
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. Multidimensional Array: Array that has more than one dimension. ...
- 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? ...
- TensorFlow良心入门教程
All the matrials come from Machine Learning class in Polyu,HK and I reorganize them and add referenc ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- [转]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 ...
- What is the fastest way of (not) logging?
原文地址:http://www.slf4j.org/faq.html#logging_performance SLF4J supports an advanced feature called par ...
- awk overview
VARIABLES, RECORDS AND FIELDS AWK variables are dynamic; they come into existence when they are fir ...
- Java Knowledge series 3
JVM & Bytecode Abstract & Object Object in Java (1) 所有东西都是对象object.可将对象想象成一种新型变量:它保存着数据,但可要求 ...
随机推荐
- MFC加载图片
目录 1. 自适应方法 2. 加载原图方法 1. 自适应方法 /* 自适应方法 */ CRect rect; CRect rect1; CImage image; //创建图片类 image.Load ...
- 最简单、最常用的一些Git命令
---------------------------------------------------------------------------------------------------- ...
- Python数据类型-1 数据类型介绍
数据类型 在python这门语言中,数据类型分为两种. 内置的和自定义的. 内置的包括数字.字符串.布尔.列表.元组.字典.Bytes.集合这些常用的以及一些不太常用的数据类型.而自定义的,一般以类的 ...
- C 语言入门第八章--C语言预处理命令
例如:#include ,这种以#号开头的命令称为预处理命令. ===C语言宏定义(#define的用法)==== #define 叫做宏定义命令,它也是C语言预处理命令的一种.所谓宏定义,就是用一个 ...
- MySQL的默认隔离级别的实现依赖于MVCC和锁,准确点说就是一致性读和锁。
MySQL的默认隔离级别的实现依赖于MVCC和锁,准确点说就是一致性读和锁.
- Ngnix简介
Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...
- js中for循环(原生js)
1,普通for循环,经常用的数组遍历 var arr = [1,2,3,4,5]; for ( var i = 0; i <arr.length; i++){ console.log(arr[i ...
- JS简单回弹原理
/* *JS简单回弹原理 */ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...
- 4 ehcache 配置
拷贝ehcache.xml文件到工程的resources目录下面 <?xml version="1.0" encoding="UTF-8"?> &l ...
- 5.1 Nginx的基本配置
备注:worker_processes 1(数量建议跟系统CPU的核数相同,例如:2个CPU,每个CPU4核,建议为8),worker_connections 建议小于worker_rlimit_no ...