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的更多相关文章

  1. numpy教程:矩阵matrix及其运算

    http://blog.csdn.net/pipisorry/article/details/48791403 numpy矩阵简介 NumPy函数库中存在两种不同的数据类型(矩阵matrix和数组ar ...

  2. 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 ...

  3. NumPy之:ndarray中的函数

    NumPy之:ndarray中的函数 目录 简介 简单函数 矢量化数组运算 条件逻辑表达式 统计方法 布尔数组 排序 文件 线性代数 随机数 简介 在NumPy中,多维数组除了基本的算数运算之外,还内 ...

  4. 利用Python进行数据分析(5) NumPy基础: ndarray索引和切片

    概念理解 索引即通过一个无符号整数值获取数组里的值. 切片即对数组里某个片段的描述. 一维数组 一维数组的索引 一维数组的索引和Python列表的功能类似: 一维数组的切片 一维数组的切片语法格式为a ...

  5. 什么是Numpy的ndarray

    什么是Numpy的ndarray 首先,Numpy的核心是ndarray. 然后,ndarray本质是数组,其不同于一般的数组,或者Python 的list的地方在于它可以有N 维(dimention ...

  6. 发现Boost官方文档的一处错误(numpy的ndarray)

    文档位置:https://www.boost.org/doc/libs/1_65_1/libs/python/doc/html/numpy/tutorial/ndarray.html shape在这里 ...

  7. Numpy:ndarray数据类型和运算

    Numpy的ndarray:一种多维数组对象 N维数组对象,该对象是一个快速而灵活的大数据集容器,nadarry是一个通用的同构数据多维容器,也就是说,其中的所有元素必须是相同类型的.每个数组都有一个 ...

  8. 理解numpy中ndarray的内存布局和设计哲学

    目录 ndarray是什么 ndarray的设计哲学 ndarray的内存布局 为什么可以这样设计 小结 参考 博客:博客园 | CSDN | blog 本文的主要目的在于理解numpy.ndarra ...

  9. NumPy之:ndarray多维数组操作

    NumPy之:ndarray多维数组操作 目录 简介 创建ndarray ndarray的属性 ndarray中元素的类型转换 ndarray的数学运算 index和切片 基本使用 index wit ...

随机推荐

  1. CSS自学笔记(11):CSS3背景和边框

    CSS3 背景 在CSS3中新增了多个关于背景的属性,可以让我们对背景有了更多更好的操作,减少用第三方工具对背景图片进行修改美化. CSS3中主要是通过定义backgrounp中的各个属性来控制背景( ...

  2. mvc 跳转到另一个页面 Controller带参数

    跳转到链接    // Controller        public ActionResult Detail(int MessageId)        {             BLL.ZQS ...

  3. securecrt在linux与windows之间传输文件(转)

    摘自:http://blog.csdn.net/rangf/article/details/6096365 SecureCRT这款SSH客户端软件同时具备了终端仿真器和文件传输功能.比ftp命令方便多 ...

  4. visibleViewController和topViewController 获取当前显示的页面

    原文:http://blog.sina.com.cn/s/blog_881ed8500102vo38.html UINavigationController 中有visibleViewControll ...

  5. android混淆打包配置(忽略第三方jar)

    在project.properties里加上   proguard.config=proguard.cfg proguard.cfg 配置如下: -optimizationpasses 5-dontu ...

  6. `npm install --save --save-exact react-native` failed

    当你使用命令行创建一个项目 react-native init  项目名称  后出现以下错误 Installing react-native package from npm... /bin/sh: ...

  7. SQL整理1 数据类型

    Character 字符串: 数据类型 描述 存储 char(n) 固定长度的字符串.最多 8,000 个字符. N的范围1-8000 varchar(n) 可变长度的字符串.最多 8,000 个字符 ...

  8. 初识Devexpress ChartControl 之 动态添加stepline及TextAnnotation

    最近在用devexpress 第三方软件做项目. devexpress 的控件使用简单.功能强大.类型丰富.界面优美.扩展性强.今天主要是动态生成了一条StepLine.生成后的效果(能力不强,所以做 ...

  9. javascript高级知识点——内置对象原型

    代码信息来自于http://ejohn.org/apps/learn/. 可以修改内置对象的方法. if (!Array.prototype.forEach) { Array.prototype.fo ...

  10. Semantic UI中的验证控件的事件的使用

    1.Semantic UI中的验证控件,功能挺不错的,中文官网的文档写的都比较详细了,我再这里就不再进行重复了,主要是想说一下它的事件的使用方法,这个可能有部分朋友刚开始接触的时候不太了解 注意看这几 ...