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 ...
随机推荐
- 《UNIX网络编程》TCP客户端服务器:并发、消息回显
经过小小改动,把前面基础的例子做出一点修改. 并发服务器,服务器每accept一个请求就fork()一个新的子进程. 编译运行方法同前一篇. /*client_tcp.c*/ #include < ...
- 【转】基于RSA算法实现软件注册码原理初讨
1 前言 目前,商用软件和共享软件绝大部份都是采用注册码授权的方式来保证软件本身不被盗用,以保证自身的利益.尽管很多常用的许多软件系统的某些版本已经被别人破解,但对于软件特殊行业而言,注册码授权的方式 ...
- shell基础——变量定义
快速参考: 变量定义格式: 变量名=值 str1="hello world" # define a string var str2=hello # define a string ...
- [问题解决] /home目录占用率100%
今天发现一个比较奇怪的现象,linux系统下一个目录挂在存储下,df -Th 显示该目录使用率100%, du 该目录显示只用了2%, 后来发现是由于进程占用了被删掉的文件空间导致.举例如下: [ro ...
- AIX 命令大全
http://www.ahinc.com/aix/general.htm http://web.mit.edu/javadev/packages/Acme/ http://jparsec.codeha ...
- Gradle DSL method not found: 'android()
原文错误提示: Error:(16, 0) Gradle DSL method not found: 'android()'Possible causes:<ul><li>Th ...
- ubuntu texlive 中文的配置方法
\documentclass[12pt]{article} \usepackage{CJKutf8} \usepackage{indentfirst}%设置第一段缩进,英语中从第二段才有缩进 \use ...
- [Leetcode][Python]19: Remove Nth Node From End of List
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 38: Count and Sayhttps://oj.leetcode.co ...
- linux 学习之九、Linux 磁盘与文件系统管理(3)
原文地址:http://vbird.dic.ksu.edu.tw/linux_basic/0230filesystem.php#filesys 创建大文件以制作 loop 装置文件!(练习非常有用) ...
- javascript的模块开发方法;
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...