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.可将对象想象成一种新型变量:它保存着数据,但可要求 ...
随机推荐
- what is 'linesize alignment' meaning?
链接: https://stackoverflow.com/questions/35678041/what-is-linesize-alignment-meaning
- JS中字符串的编码 解码
DEPTNAME 是一个字符串 编码: DEPTNAME = encodeURI(encodeURI(DEPTNAME)); 解码: DEPTNAME = decodeURI(DEPTNAME,&qu ...
- Servlet对用户输入的数据进行读取
逻辑代码: package com.zyb.test; import java.io.IOException; import java.util.Enumeration; import javax.s ...
- delphi IdSMTP发送邮件
TIdPOP3组件简介 TIdPOP3 是用来接收邮件服务器的邮件信息到用户端的一个组件.它实现了RFC 1939协议. 在使用TIdPOP3组件时需设置它的几个成员属性. Host :指定邮件服务器 ...
- INUX下抓取当前登录用户登录密码的工具:mimipenguin
前有Mimikatz,今有mimipenguin,近日国外安全研究员huntergregal发布了工具mimipenguin,一款Linux下的密码抓取神器,可以说弥补了Linux下密码抓取的空缺. ...
- Liunx 如何查看80端口被哪个程序所占用
场景:启服务时一直报80端口被占用 解决方: 1.首先查看下 80 端口的使用情况 netstat -anp|grep 80 查看80端口被被占用的PID 2.根据这个PID 来查看被哪个程序在使用 ...
- kibana 删除document或者type
// 删除某个document DELETE /索引名称/type名称/document编号(id) // 删除整个type PUT 索引名称/type名称/_delete_by_query?conf ...
- Python 类型转换指南
一.int型 支持转换为 int 类型的,仅有 float.str.bytes,其他类型均不支持. 1.float -> int会去掉小数点及后面的数值,仅保留整数部分. 2.str -> ...
- Linux用户和用户组管理命令
一.用户管理命令 1.useradd 创建用户或更新默认新用户的信息 使用方法 useradd [options] 用户名 选项: useradd -u 指定UID具体数值, ...
- Tomcat能启动,无法访问方法,
好像没有扫描到controller 好像配置文件都没有加载成功 项目启动后,目录下多出一个ssmtest.xml文件 D:\Program Files\JDK-tomcat\apache-tomcat ...