标签: Numpy

21 篇文章

035、一般函数
一般函数 import numpy as np 三角函数 sin(x) cos(x) tan(x) sinh(x) conh(x) tanh(x) arccos(x) arctan(x) arcsin(x) arccosh(x) arctanh(x) arcsinh(x) arctan2(x,y) arctan2(x,y) 返回 arctan(x/y) 。 向量操作 dot(x,y) inner(…
034、矩阵
矩阵 使用 mat 方法将 2 维数组转化为矩阵: import numpy as np a = np.array([[1,2,4], [2,5,3], [7,8,9]]) A = np.mat(a) A matrix([[1, 2, 4], [2, 5, 3], [7, 8, 9]]) 也可以使用 Matlab 的语法传入一个字符串来生成矩阵: A = np.mat('1,2,4;2,…
033、生成数组的函数
生成数组的函数 arange arange 类似于Python中的 range 函数,只不过返回的不是列表,而是数组: arange(start, stop=None, step=1, dtype=None) 产生一个在区间 [start, stop) 之间,以 step 为间隔的数组,如果只输入一个参数,则默认从 0 开始,并以这个值为结束: import numpy as np np.aran…
032、对角线
对角线 这里,使用与之前不同的导入方法: import numpy as np 使用numpy中的函数前,需要加上 np.: a = np.array([11,21,31,12,22,32,13,23,33]) a.shape = 3,3 a array([[11, 21, 31], [12, 22, 32], [13, 23, 33]]) 查看它的对角线元素: a.diagonal() arra…
031、数组形状
数组形状 %pylab Using matplotlib backend: Qt4Agg Populating the interactive namespace from numpy and matplotlib 修改数组的形状 a = arange(6) a array([0, 1, 2, 3, 4, 5]) 将形状修改为2乘3: a.shape = 2,3 a array([[0, 1, 2…
030、数组排序
数组排序 %pylab Using matplotlib backend: Qt4Agg Populating the interactive namespace from numpy and matplotlib sort 函数 先看这个例子: names = array(['bob', 'sue', 'jan', 'ad&#…
029、数组方法
数组方法 %pylab Using matplotlib backend: Qt4Agg Populating the interactive namespace from numpy and matplotlib 求和 a = array([[1,2,3], [4,5,6]]) 求所有元素的和: sum(a) 21 指定求和的维度: 沿着第一维求和: sum(a, axis=0) array([…
028、数组类型
数组类型 from numpy import * 之前已经看过整数数组和布尔数组,除此之外还有浮点数数组和复数数组。 复数数组 产生一个复数数组: a = array([1 + 1j, 2, 3, 4]) Python会自动判断数组的类型: a.dtype dtype('complex128') 对于复数我们可以查看它的实部和虚部: a.real array([ 1., 2., 3., 4.]) …
027、Numpy 数组及其索引
Numpy 数组及其索引 先导入numpy: from numpy import * 产生数组 从列表产生数组: lst = [0, 1, 2, 3] a = array(lst) a array([0, 1, 2, 3]) 或者直接将列表传入: a = array([1, 2, 3, 4]) a array([1, 2, 3, 4]) 数组属性 查看类型: type(a) numpy.ndarr…
026、Matplotlib 基础
Matplotlib 基础 在使用Numpy之前,需要了解一些画图的基础。 Matplotlib是一个类似Matlab的工具包,主页地址为 http://matplotlib.org 导入 matplotlib 和 numpy: %pylab Using matplotlib backend: Qt4Agg Populating the interactive namespace from num…