Numpy之ndarray与matrix
1. ndarray对象
ndarray是numpy中的一个N维数组对象,可以进行矢量算术运算,它是一个通用的同构数据多维容器,即其中的所有元素必须是相同类型的。
可以使用array函数创建数组,每个数组都有一个shape(一个表示各维度大小的元组)和一个dtype(一个用于说明数组数据类型的对象)。


使用zeros和ones函数可以分别创建数据全0或全1的数组。
numpy.ones(shape, dtype=None,order='C'):其中shape表示返回数组的形状;dtype表示数组数据的类型,默认为float64;order可以取'C'或'F',表示是否在内存中用C或者Fortran形式以连续顺序(row- or column-wise)存放多维数据。

2. matrix对象
numpy库提供了matrix类,使用matrix类创建的是matrix对象。matrix对象是继承ndarray而来,因此它们和ndarray有相同的属性和方法。但是它们之间有六个重要的区别,使用时一定要注意:
1) Matrix objects can be created using a string notation to allow Matlab-style syntax where spaces separate columns and semicolons (‘;’) separate rows.
2) Matrix objects are always two-dimensional. This has far-reaching implications, in that m.ravel() is still two-dimensional (with a 1 in the first dimension) and item selection returns two-dimensional objects so that sequence behavior is fundamentally different than arrays.
3) Matrix objects over-ride multiplication to be matrix-multiplication. Make sure you understand this for functions that you may want to receive matrices. Especially in light of the fact that asanyarray(m) returns a matrix when m is a matrix.
4) Matrix objects over-ride power to be matrix raised to a power. The same warning about using power inside a function that uses asanyarray(...) to get an array object holds for this fact.
5) The default __array_priority__ of matrix objects is 10.0, and therefore mixed operations with ndarrays always produce matrices.
6) Matrices have special attributes which make calculations easier. These are

使用numpy.matrix可以创建一个矩阵对象,numpy.mat是它的缩写。它可以根据其他matrixs,字符串,或者其他可以转化为ndarray的数据创建新的矩阵对象。

Numpy之ndarray与matrix的更多相关文章
- numpy教程:矩阵matrix及其运算
http://blog.csdn.net/pipisorry/article/details/48791403 numpy矩阵简介 NumPy函数库中存在两种不同的数据类型(矩阵matrix和数组ar ...
- python中ndarray和matrix
1. 定义ndarray和matrix from numpy import * a = mat([[1,2],[3,4]]) b = mat([[5,6],[7,8]]) c = array([1,2 ...
- NumPy之:ndarray中的函数
NumPy之:ndarray中的函数 目录 简介 简单函数 矢量化数组运算 条件逻辑表达式 统计方法 布尔数组 排序 文件 线性代数 随机数 简介 在NumPy中,多维数组除了基本的算数运算之外,还内 ...
- 利用Python进行数据分析(5) NumPy基础: ndarray索引和切片
概念理解 索引即通过一个无符号整数值获取数组里的值. 切片即对数组里某个片段的描述. 一维数组 一维数组的索引 一维数组的索引和Python列表的功能类似: 一维数组的切片 一维数组的切片语法格式为a ...
- 什么是Numpy的ndarray
什么是Numpy的ndarray 首先,Numpy的核心是ndarray. 然后,ndarray本质是数组,其不同于一般的数组,或者Python 的list的地方在于它可以有N 维(dimention ...
- 发现Boost官方文档的一处错误(numpy的ndarray)
文档位置:https://www.boost.org/doc/libs/1_65_1/libs/python/doc/html/numpy/tutorial/ndarray.html shape在这里 ...
- Numpy:ndarray数据类型和运算
Numpy的ndarray:一种多维数组对象 N维数组对象,该对象是一个快速而灵活的大数据集容器,nadarry是一个通用的同构数据多维容器,也就是说,其中的所有元素必须是相同类型的.每个数组都有一个 ...
- 理解numpy中ndarray的内存布局和设计哲学
目录 ndarray是什么 ndarray的设计哲学 ndarray的内存布局 为什么可以这样设计 小结 参考 博客:博客园 | CSDN | blog 本文的主要目的在于理解numpy.ndarra ...
- NumPy之:ndarray多维数组操作
NumPy之:ndarray多维数组操作 目录 简介 创建ndarray ndarray的属性 ndarray中元素的类型转换 ndarray的数学运算 index和切片 基本使用 index wit ...
随机推荐
- div模拟textarea以实现高度自适应实例页面
作为多行文本域功能来讲,textarea满足了我们大部分的需求.然而,textarea有一个不足就是不能像普通div标签一样高度可以跟随内容自适应.textarea总是很自信地显摆它的滚动条,高度固执 ...
- Flask中endpoint的理解
在flask框架中,我们经常会遇到endpoint这个东西,最开始也没法理解这个到底是做什么的.最近正好在研究Flask的源码,也就顺带了解了一下这个endpoint 首先,我们看一个例子: @app ...
- 解除被DenyHosts锁定的IP地址
自己的本本无法ssh上服务器,提示 ssh_exchange_identification: read: Connection reset by peer 仔细回想,自己手贱把~下面的一个ssh文件删 ...
- Hadoop4Win
Hadoop4Win + Eclipse 运行 WordCount 程序 http://software.intel.com/zh-cn/blogs/2013/10/16/hadoop4win-ecl ...
- Aix6.1安装openssh
一.软件下载 1.官方网站下载: openssl IBM官方网站下载:https://www14.software.ibm.com/webapp/iwm/web/reg/download.do?sou ...
- Is life always hard?
原文来自我的独立blog: http://www.yuanyong.org/blog/midnightsun/is-life-always-hard 和两个朋友聊天. 小L在考研,打电话过去的时候小L ...
- c++犯过的严重错误
1.if(num == 0)写成了if(num = 0)导致软件运行一直崩溃且找不到原因,浪费了很大的代价,以后我写这种语法的时候一直写if(0 == num) 2.if (sting.find(&q ...
- ros消息时间同步与回调
转载自http://blog.csdn.net/zyh821351004/article/details/47758433 方式一: 全局变量形式 : TimeSynchronizer 步骤: 1. ...
- sharepoint 2013 reporting services 远程server返回错误: (500) 内部server错误。
在sharepoint 2013部署reporting services过程中,点击管理中心,server上的服务.系统配置.提示了一个错误: 远程server返回错误: (500) 内部server ...
- Swfit中视图跳转
.跳转到任一UIViewController var sb = UIStoryboard(name: "Main", bundle:nil) var vc = sb.instant ...