numpy
文章
11数学运算
数学函数(Mathematical functions)三角函数 method description sin(x, /[, out, where, casting, order, …]) 正弦函数, element-wise. cos(x, /[, out, where, casting, order, …]) 余弦函数 element-wise. tan(x, /[, out, where, casting, order, …]) 正切函数, element-wise. arcsin(x, /[, out, where, casting, order, …]) 反正弦函数, element-wise. arccos(x, /[, out, where, casting, order, …]) 反余弦函数, element-wise. arctan(x, /[, out, where, casting, order, …]) 反正切函数, element-wise. hypot(x1,...
12统计运算
StatisticsOrder statistics method description amin(a[, axis, out, keepdims, initial, where]) Return the minimum of an array or minimum along an axis. amax(a[, axis, out, keepdims, initial, where]) Return the maximum of an array or maximum along an axis. nanmin(a[, axis, out, keepdims]) Return minimum of an array or minimum along an axis, ignoring any NaNs. nanmax(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis, ignoring any NaNs. ptp(a[, axis, ou...
13排序搜索
排序,搜索和计数(Sorting, searching, and counting)排序(Sorting) method description sort(a[, axis, kind, order]) 返回数组的排序副本。 lexsort(keys[, axis]) 使用键的序列执行间接稳定排序。 argsort(a[, axis, kind, order]) 返回将对数组进行排序的索引。 ndarray.sort([axis, kind, order]) 就地排序数组。 msort(a) 返回沿第一个指针排序的数组的副本。 sort_complex(a) 首先使用实部,然后使用虚部对复杂数组进行排序。 partition(a, kth[, axis, kind, order]) 返回数组的分区副本。 argpartition(a, kth[, axis, kind, order]) 使用kind关键字指定的算法,沿给定的指针执行间接分区。 Searching method description argmax(a[, axi...
14字节交换
在几乎所有的机器上,多字节对象都被存储为连续的字节序列。字节顺序,是跨越多字节的程序对象的存储规则。 大端模式:指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中,这样的存储模式有点儿类似于把数据当作字符串顺序处理:地址由小向大增加,而数据从高位往低位放;这和我们的阅读习惯一致。 小端模式:指数据的高字节保存在内存的高地址中,而数据的低字节保存在内存的低地址中,这种存储模式将地址的高低和数据位权有效地结合起来,高地址部分权值高,低地址部分权值低。 numpy.ndarray.byteswap()1234567891011121314151617181920212223import numpy as np a = np.array([1, 256, 8755], dtype = np.int16) print ('我们的数组是:')print (a)print ('以十六进制表示内存中的数据:')print (map(hex,a))# byteswap() 函数通过传入 true 来原地交换 print (...
15线性代数
线性代数(numpy.linalg)NumPy线性代数函数依赖于BLAS和LAPACK来提供标准线性代数算法的高效低级实现。这些库可以由NumPy本身使用其参考实现子集的C版本提供,但如果可能,最好是利用专用处理器功能的高度优化的库。这样的库的例子是OpenBLAS、MKL(TM)和ATLAS。因为这些库是多线程和处理器相关的,所以可能需要环境变量和外部包(如threadpoolctl)来控制线程数量或指定处理器体系结构。 矩阵和向量积 方法 描述 dot(a, b[, out]) 两个数组的点积。 linalg.multi_dot(arrays) 在单个函数调用中计算两个或更多数组的点积,同时自动选择最快的求值顺序。 vdot(a, b) 返回两个向量的点积。 inner(a, b) 两个数组的内积。 outer(a, b[, out]) 计算两个向量的外积。 matmul(x1, x2, /[, out, casting, order, …]) 两个数组的矩阵乘积。 tensordot(a, b[, axes]) 沿指定轴计算张量点...
16IO
输入和输出NumPy二进制文件(NPY,NPZ) 方法 描述 load(file[, mmap_mode, allow_pickle, …]) 从.npy、.npz或pickle文件加载阵列或pickle对象。 save(file, arr[, allow_pickle, fix_imports]) 将数组保存为NumPy.npy格式的二进制文件。 savez(file, *args, **kwds) 将几个数组以未压缩的.npz格式保存到单个文件中。 savez_compressed(file, *args, **kwds) 以压缩的.npz格式将几个数组保存到单个文件中。 有关这些二进制文件类型的格式,请参阅numpy.lib.format 文本文件 方法 描述 loadtxt(fname[, dtype, comments, delimiter, …]) 从文本文件加载数据。 savetxt(fname, X[, fmt, delimiter, newline, …]) 将数组保存到文本文件。 genfromtxt(fname[,...
17逻辑运算
逻辑函数真值测试 方法 描述 all(a[, axis, out, keepdims]) 测试是否沿给定轴的所有数组元素求值为True。 any(a[, axis, out, keepdims]) 测试沿给定轴的任何数组元素的求值是否为True。 数组内容 方法 描述 isfinite(x, /[, out, where, casting, order, …]) 逐一测试有限性(不是无穷大还是不是数字)。 isinf(x, /[, out, where, casting, order, …]) 逐元素测试正无穷大或负无穷大。 isnan(x, /[, out, where, casting, order, …]) 对NaN逐个元素进行测试,并将结果作为布尔数组返回。 isnat(x, /[, out, where, casting, order, …]) 对NaT(不是时间)逐个元素进行测试,然后将结果作为布尔数组返回。 isneginf(x[, out]) 逐项测试负无穷大,将结果作为布尔数组返...
18矩阵库
矩阵库 (numpy.matlib)该模块包含 numpy 命名空间中的所有函数, 以下返回 矩阵 而不是 ndarrays的替换函数。 也在numpy命名空间中的函数并返回矩阵 method description mat(data[, dtype]) 将输入解释为 矩阵. matrix(data[, dtype, copy]) 注意:不再建议使用此类,即使对于线性 asmatrix(data[, dtype]) 将输入解释为矩阵。 bmat(obj[, ldict, gdict]) 从字符串,嵌套序列或数组构建矩阵对象。 matlib的替换函数 method description empty(shape[, dtype, order]) 返回给定形状和类型的新矩阵,而无需初始化条目。 zeros(shape[, dtype, order]) 返回给定形状和类型的矩阵,并用零填充。 ones(shape[, dtype, order]) 一个矩阵。 eye(n[, M, k, dtype, order]) 返回一个矩阵,在...
19多项式
basic API poly1d(c_or_r[, r, variable]) A one-dimensional polynomial class. polyval(p, x) Evaluate a polynomial at specific values. poly(seq_of_zeros) Find the coefficients of a polynomial with the given sequence of roots. roots(p) Return the roots of a polynomial with coefficients given in p. filter polyfit(x, y, deg[, rcond, full, w, cov]) Least squares polynomial fit. calculus polyder(p[, m]) Return the derivative of the specified order of a polynomial. polyint(p[, m, ...
20随机数
使用numpy产生随机数numpy中的random模块包含了很多方法可以用来产生随机数,这篇文章将对random中的一些常用方法做一个总结。 1、numpy.random.rand(d0, d1, …, dn) 作用:产生一个给定形状的数组(其实应该是ndarray对象或者是一个单值),数组中的值服从[0, 1)之间的均匀分布。 参数:d0, d, …, dn : int,可选。如果没有参数则返回一个float型的随机数,该随机数服从[0, 1)之间的均匀分布。 返回值:ndarray对象或者一个float型的值例子: 123456789101112# [0, 1)之间均匀分布的随机数,3行2列a = np.random.rand(3, 2)print(a)# 不提供形状b = np.random.rand()print(b)输出:[[0.26054323 0.28184468] [0.7783674 0.71733674] [0.90302256 0.49303252]]0.6022098740124009 2、numpy.random.uniform(low=0...












