多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 2.7。支持的 NumPy 功能 > 原文: [http://numba.pydata.org/numba-doc/latest/reference/numpysupported.html](http://numba.pydata.org/numba-doc/latest/reference/numpysupported.html) 注意 支持绝大多数 NumPy 1.16 行为,但涉及`NaT`的`datetime`和`timedelta`使用与早期版本中存在的行为相匹配。 ufunc 套件尚未扩展以适应 NumPy 1.16 中存在的两个新的时间计算相关的附加功能。此外,在某些输入模式中出现`NaN`时,`ediff1d`和`interp`函数在复制输出方面存在一些小问题。 Numba 的一个目标是与 [NumPy](http://www.numpy.org/) 无缝集成。 NumPy 数组为同类数据集提供了一种有效的存储方法。 NumPy dtypes 在编译时提供有用的类型信息,并且内存中潜在大量数据的常规结构化存储为代码生成提供了理想的内存布局。 Numba 擅长生成在 NumPy 数组之上执行的代码。 NumbP 在 Numba 的支持有多种形式: * Numba 了解对 NumPy [ufuncs](http://docs.scipy.org/doc/numpy/reference/ufuncs.html) 的调用,并能够为其中许多人生成等效的本机代码。 * Numba 直接支持 NumPy 阵列。访问 Numpy 数组非常有效,因为索引会降低到可能时直接访问内存。 * Numba 能够产生 [ufuncs](http://docs.scipy.org/doc/numpy/reference/ufuncs.html) 和 [gufuncs](http://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html) 。这意味着可以在 Python 中实现 ufuncs 和 gufunc,使用 NumPy C API 获得与 C 扩展模块中实现的 ufuncs / gufuncs 相当的速度。 除非另有说明,否则以下部分将重点介绍 [nopython 模式](../glossary.html#term-nopython-mode)中支持的 Numpy 功能。 ## 2.7.1。标量类型 Numba 支持以下 Numpy 标量类型: * **整数**:所有符号的整数,以及最多 64 位的任何宽度 * **布尔** * **实数:**单精度(32 位)和双精度(64 位)实数 * **复数:**单精度(2x32 位)和双精度(2x64 位)复数 * **日期时间和时间戳:任何单位的** * **字符序列**(但没有可用的操作) * **结构化标量:**结构标量由上述任何类型和上述类型的数组组成 不支持以下标量类型和功能: * **任意 Python 对象** * **半精度和扩展精度**实数和复数 * **嵌套结构化标量**结构化标量字段可能不包含其他结构化标量 标量 Numpy 数字支持的操作与`int`或`float`等效内置类型相同。您可以使用类型的构造函数从不同的类型或宽度进行转换。 结构化标量支持属性获取和设置,以及使用常量字符串的成员查找。 也可以看看 [Numpy scalars](http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html) 参考。 ## 2.7.2。数组类型 [支持上述任何标量类型的 Numpy 数组](http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html),无论其形状或布局如何。 ### 2.7.2.1。数组访问 数组支持正常迭代。支持完整的基本索引和切片。还支持高级索引的子集:只允许一个高级索引,它必须是一维数组(它也可以与任意数量的基本索引组合)。 也可以看看 [Numpy 索引](http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html)参考。 ### 2.7.2.2。属性 支持 Numpy 数组的以下属性: * [`dtype`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.dtype.html#numpy.ndarray.dtype "(in NumPy v1.16)") * [`flags`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flags.html#numpy.ndarray.flags "(in NumPy v1.16)") * [`flat`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flat.html#numpy.ndarray.flat "(in NumPy v1.16)") * [`itemsize`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.itemsize.html#numpy.ndarray.itemsize "(in NumPy v1.16)") * [`ndim`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.ndim.html#numpy.ndarray.ndim "(in NumPy v1.16)") * [`shape`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.shape.html#numpy.ndarray.shape "(in NumPy v1.16)") * [`size`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.size.html#numpy.ndarray.size "(in NumPy v1.16)") * [`strides`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.strides.html#numpy.ndarray.strides "(in NumPy v1.16)") * [`T`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.T.html#numpy.ndarray.T "(in NumPy v1.16)") * [`real`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.real.html#numpy.ndarray.real "(in NumPy v1.16)") * [`imag`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.imag.html#numpy.ndarray.imag "(in NumPy v1.16)") #### 2.7.2.2.1。 `flags`对象 [`flags`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flags.html#numpy.ndarray.flags "(in NumPy v1.16)") 属性返回的对象支持`contiguous`,`c_contiguous`和`f_contiguous`属性。 #### 2.7.2.2.2。 `flat`对象 [`flat`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flat.html#numpy.ndarray.flat "(in NumPy v1.16)") 属性返回的对象支持迭代和索引,但要小心:非 C 连续数组的索引非常慢。 #### 2.7.2.2.3。 `real`和`imag`属性 无论 dtype 如何,Numpy 都支持这些属性,但 Numba 选择限制其支持以避免潜在的用户错误。对于数字 dtypes,Numba 遵循 Numpy 的行为。 [`real`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.real.html#numpy.ndarray.real "(in NumPy v1.16)") 属性返回复数数组实部的视图,它表现为其他数字 dtypes 的标识函数。 [`imag`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.imag.html#numpy.ndarray.imag "(in NumPy v1.16)") 属性返回复数数组的虚部的视图,并返回具有相同形状的零数组和其他数字 dtypes 的 dtype。对于非数字 dtypes,包括所有结构化/记录 dtypes,使用这些属性将导致编译时( <cite>TypingError</cite> )错误。此行为与 Numpy 不同,但选择此行为是为了避免与重叠这些属性的字段名称混淆。 ### 2.7.2.3。计算 Numpy 数组的以下方法以其基本形式支持(没有任何可选参数): * [`all()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.all.html#numpy.ndarray.all "(in NumPy v1.16)") * [`any()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.any.html#numpy.ndarray.any "(in NumPy v1.16)") * [`argmax()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.argmax.html#numpy.ndarray.argmax "(in NumPy v1.16)") * [`argmin()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.argmin.html#numpy.ndarray.argmin "(in NumPy v1.16)") * [`conj()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.conj.html#numpy.ndarray.conj "(in NumPy v1.16)") * [`conjugate()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.conjugate.html#numpy.ndarray.conjugate "(in NumPy v1.16)") * [`cumprod()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.cumprod.html#numpy.ndarray.cumprod "(in NumPy v1.16)") * [`cumsum()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.cumsum.html#numpy.ndarray.cumsum "(in NumPy v1.16)") * [`max()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.max.html#numpy.ndarray.max "(in NumPy v1.16)") * [`mean()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.mean.html#numpy.ndarray.mean "(in NumPy v1.16)") * [`min()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.min.html#numpy.ndarray.min "(in NumPy v1.16)") * [`nonzero()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.nonzero.html#numpy.ndarray.nonzero "(in NumPy v1.16)") * [`prod()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.prod.html#numpy.ndarray.prod "(in NumPy v1.16)") * [`std()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.std.html#numpy.ndarray.std "(in NumPy v1.16)") * [`take()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.take.html#numpy.ndarray.take "(in NumPy v1.16)") * [`var()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.var.html#numpy.ndarray.var "(in NumPy v1.16)") 相应的顶级 Numpy 函数(例如 [`numpy.prod()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.prod.html#numpy.prod "(in NumPy v1.16)") )也同样受支持。 ### 2.7.2.4。其他方法 支持以下 Numpy 数组方法: * [`argsort()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.argsort.html#numpy.ndarray.argsort "(in NumPy v1.16)") (值`'quicksort'`和`'mergesort'`支持`kind`关键字参数) * [`astype()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.astype.html#numpy.ndarray.astype "(in NumPy v1.16)") (仅 1 参数形式) * [`copy()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.copy.html#numpy.ndarray.copy "(in NumPy v1.16)") (不带参数) * [`dot()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.dot.html#numpy.ndarray.dot "(in NumPy v1.16)") (仅 1 参数形式) * [`flatten()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flatten.html#numpy.ndarray.flatten "(in NumPy v1.16)") (无订单参数;仅'C'订单) * [`item()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.item.html#numpy.ndarray.item "(in NumPy v1.16)") (不带参数) * [`itemset()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.itemset.html#numpy.ndarray.itemset "(in NumPy v1.16)") (仅 1 参数形式) * [`ravel()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.ravel.html#numpy.ndarray.ravel "(in NumPy v1.16)") (无订单参数;仅'C'订单) * [`reshape()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.reshape.html#numpy.ndarray.reshape "(in NumPy v1.16)") (仅 1 参数形式) * [`sort()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.sort.html#numpy.ndarray.sort "(in NumPy v1.16)") (不带参数) * [`sum()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.sum.html#numpy.ndarray.sum "(in NumPy v1.16)") (有或没有`axis`参数) * 如果`axis`参数是编译时常量,则支持所有有效值。超出范围的值将在编译时产生`LoweringError`。 * 如果`axis`参数不是编译时常量,则仅支持 0 到 3 之间的值。超出范围的值将导致运行时异常。 * [`transpose()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.transpose.html#numpy.ndarray.transpose "(in NumPy v1.16)") * [`view()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.view.html#numpy.ndarray.view "(in NumPy v1.16)") (仅 1 参数形式) 警告 排序可能比 Numpy 的实现略慢。 ## 2.7.3。功能 ### 2.7.3.1。线性代数 浮点数和复数的 1-D 和 2-D 连续数组支持基本线性代数: * [`numpy.dot()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.html#numpy.dot "(in NumPy v1.16)") * [`numpy.kron()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.kron.html#numpy.kron "(in NumPy v1.16)") * [`numpy.outer()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.outer.html#numpy.outer "(in NumPy v1.16)") * [`numpy.trace()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.trace.html#numpy.trace "(in NumPy v1.16)") (只有第一个参数)。 * [`numpy.vdot()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.vdot.html#numpy.vdot "(in NumPy v1.16)") * 在 Python 3.5 及更高版本中,来自 [**PEP 465**](https://www.python.org/dev/peps/pep-0465)的矩阵乘法运算符(即`a @ b`,其中`a`和`b`是 1-D 或 2-D 阵列)。 * [`numpy.linalg.cholesky()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.cholesky.html#numpy.linalg.cholesky "(in NumPy v1.16)") * [`numpy.linalg.cond()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.cond.html#numpy.linalg.cond "(in NumPy v1.16)") (`p`中只有非字符串值)。 * [`numpy.linalg.det()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.det.html#numpy.linalg.det "(in NumPy v1.16)") * [`numpy.linalg.eig()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eig.html#numpy.linalg.eig "(in NumPy v1.16)") (仅支持运行不会导致域更改的数据,例如实数输入 - >实数输出,复数输入 - >复数输出)。 * [`numpy.linalg.eigh()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eigh.html#numpy.linalg.eigh "(in NumPy v1.16)") (只有第一个参数)。 * [`numpy.linalg.eigvals()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eigvals.html#numpy.linalg.eigvals "(in NumPy v1.16)") (仅支持运行不会导致域更改的数据,例如实数输入 - >实数输出,复数输入 - >复数输出)。 * [`numpy.linalg.eigvalsh()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eigvalsh.html#numpy.linalg.eigvalsh "(in NumPy v1.16)") (只有第一个参数)。 * [`numpy.linalg.inv()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html#numpy.linalg.inv "(in NumPy v1.16)") * [`numpy.linalg.lstsq()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.lstsq.html#numpy.linalg.lstsq "(in NumPy v1.16)") * [`numpy.linalg.matrix_power()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.matrix_power.html#numpy.linalg.matrix_power "(in NumPy v1.16)") * [`numpy.linalg.matrix_rank()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.matrix_rank.html#numpy.linalg.matrix_rank "(in NumPy v1.16)") * [`numpy.linalg.norm()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html#numpy.linalg.norm "(in NumPy v1.16)") (只有 2 个第一个参数,`ord`中只有非字符串值)。 * [`numpy.linalg.pinv()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.pinv.html#numpy.linalg.pinv "(in NumPy v1.16)") * [`numpy.linalg.qr()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.qr.html#numpy.linalg.qr "(in NumPy v1.16)") (只有第一个参数)。 * [`numpy.linalg.slogdet()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.slogdet.html#numpy.linalg.slogdet "(in NumPy v1.16)") * [`numpy.linalg.solve()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html#numpy.linalg.solve "(in NumPy v1.16)") * [`numpy.linalg.svd()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.svd.html#numpy.linalg.svd "(in NumPy v1.16)") (只有 2 个第一个参数)。 注意 这些功能的实现需要安装 Scipy 0.16+。 ### 2.7.3.2。减少 支持以下缩减功能: * [`numpy.diff()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.diff.html#numpy.diff "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.median()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.median.html#numpy.median "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nancumprod()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nancumprod.html#numpy.nancumprod "(in NumPy v1.16)") (只有第一个参数,需要 NumPy> = 1.12)) * [`numpy.nancumsum()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nancumsum.html#numpy.nancumsum "(in NumPy v1.16)") (只有第一个参数,需要 NumPy> = 1.12)) * [`numpy.nanmax()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanmax.html#numpy.nanmax "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nanmean()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanmean.html#numpy.nanmean "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nanmedian()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanmedian.html#numpy.nanmedian "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nanmin()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanmin.html#numpy.nanmin "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nanpercentile()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanpercentile.html#numpy.nanpercentile "(in NumPy v1.16)") (只有 2 个第一个参数,需要 NumPy> = 1.11) * [`numpy.nanprod()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanprod.html#numpy.nanprod "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nanstd()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanstd.html#numpy.nanstd "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nansum()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nansum.html#numpy.nansum "(in NumPy v1.16)") (只有第一个参数) * [`numpy.nanvar()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanvar.html#numpy.nanvar "(in NumPy v1.16)") (只有第一个参数) * [`numpy.percentile()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.percentile.html#numpy.percentile "(in NumPy v1.16)") (只有 2 个第一个参数,需要 NumPy> = 1.10) ### 2.7.3.3。其他功能 支持以下顶级功能: * [`numpy.arange()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange "(in NumPy v1.16)") * [`numpy.argsort()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html#numpy.argsort "(in NumPy v1.16)") (值`'quicksort'`和`'mergesort'`支持`kind`关键字参数) * [`numpy.array()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html#numpy.array "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.asarray()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html#numpy.asarray "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.asfortranarray()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.asfortranarray.html#numpy.asfortranarray "(in NumPy v1.16)") (只有第一个参数) * [`numpy.atleast_1d()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.atleast_1d.html#numpy.atleast_1d "(in NumPy v1.16)") * [`numpy.atleast_2d()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.atleast_2d.html#numpy.atleast_2d "(in NumPy v1.16)") * [`numpy.atleast_3d()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.atleast_3d.html#numpy.atleast_3d "(in NumPy v1.16)") * [`numpy.bincount()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.bincount.html#numpy.bincount "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.column_stack()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.column_stack.html#numpy.column_stack "(in NumPy v1.16)") * [`numpy.concatenate()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html#numpy.concatenate "(in NumPy v1.16)") * [`numpy.convolve()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.convolve.html#numpy.convolve "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.copy()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.copy.html#numpy.copy "(in NumPy v1.16)") (只有第一个参数) * [`numpy.corrcoef()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.corrcoef.html#numpy.corrcoef "(in NumPy v1.16)") (只有 3 个第一个参数,需要 NumPy> = 1.10 和 SciPy> = 0.16;每个 NumPy 1.11+的极值处理) * [`numpy.correlate()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.correlate.html#numpy.correlate "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.cov()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.cov.html#numpy.cov "(in NumPy v1.16)") (只有 5 个第一个参数,需要 NumPy> = 1.10,SciPy> = 0.16) * [`numpy.diag()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.diag.html#numpy.diag "(in NumPy v1.16)") * [`numpy.digitize()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.digitize.html#numpy.digitize "(in NumPy v1.16)") * [`numpy.dstack()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.dstack.html#numpy.dstack "(in NumPy v1.16)") * `numpy.dtype()`(只有第一个参数) * [`numpy.ediff1d()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ediff1d.html#numpy.ediff1d "(in NumPy v1.16)") * [`numpy.empty()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.empty.html#numpy.empty "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.empty_like()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.empty_like.html#numpy.empty_like "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.expand_dims()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.expand_dims.html#numpy.expand_dims "(in NumPy v1.16)") * [`numpy.extract()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.extract.html#numpy.extract "(in NumPy v1.16)") * [`numpy.eye()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.eye.html#numpy.eye "(in NumPy v1.16)") * [`numpy.fill_diagonal()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.fill_diagonal.html#numpy.fill_diagonal "(in NumPy v1.16)") * `numpy.flatten()`(无订单参数;仅'C'订单) * [`numpy.frombuffer()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.frombuffer.html#numpy.frombuffer "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.full()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.full.html#numpy.full "(in NumPy v1.16)") (只有 3 个第一个参数) * [`numpy.full_like()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.full_like.html#numpy.full_like "(in NumPy v1.16)") (只有 3 个第一个参数) * [`numpy.histogram()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html#numpy.histogram "(in NumPy v1.16)") (只有 3 个第一个参数) * [`numpy.hstack()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.hstack.html#numpy.hstack "(in NumPy v1.16)") * [`numpy.identity()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.identity.html#numpy.identity "(in NumPy v1.16)") * [`numpy.interp()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html#numpy.interp "(in NumPy v1.16)") (只有 3 个第一个参数;需要 NumPy> = 1.10;每个 NumPy 1.12+的复杂 dtype 处理; `xp`必须单调递增) * [`numpy.linspace()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html#numpy.linspace "(in NumPy v1.16)") (只有 3 参数形式) * [`numpy.ndenumerate`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndenumerate.html#numpy.ndenumerate "(in NumPy v1.16)") * [`numpy.ndindex`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndindex.html#numpy.ndindex "(in NumPy v1.16)") * [`numpy.nditer`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nditer.html#numpy.nditer "(in NumPy v1.16)") (只有第一个参数) * [`numpy.ones()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ones.html#numpy.ones "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.ones_like()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ones_like.html#numpy.ones_like "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.partition()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.partition.html#numpy.partition "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.ptp()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ptp.html#numpy.ptp "(in NumPy v1.16)") (只有第一个参数) * [`numpy.ravel()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html#numpy.ravel "(in NumPy v1.16)") (无订单参数;仅'C'订单) * [`numpy.reshape()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html#numpy.reshape "(in NumPy v1.16)") (无订单参数;仅'C'订单) * [`numpy.roll()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.roll.html#numpy.roll "(in NumPy v1.16)") (只有 2 个第一个参数;第二个参数`shift`必须是整数) * [`numpy.roots()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.roots.html#numpy.roots "(in NumPy v1.16)") * [`numpy.round_()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.round_.html#numpy.round_ "(in NumPy v1.16)") * [`numpy.searchsorted()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.searchsorted.html#numpy.searchsorted "(in NumPy v1.16)") (只有 3 个第一个参数) * [`numpy.sinc()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.sinc.html#numpy.sinc "(in NumPy v1.16)") * [`numpy.sort()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.sort.html#numpy.sort "(in NumPy v1.16)") (无可选参数) * [`numpy.stack()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.stack.html#numpy.stack "(in NumPy v1.16)") * [`numpy.take()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.take.html#numpy.take "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.transpose()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html#numpy.transpose "(in NumPy v1.16)") * [`numpy.trapz()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.trapz.html#numpy.trapz "(in NumPy v1.16)") (只有 3 个第一个参数) * [`numpy.tri()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.tri.html#numpy.tri "(in NumPy v1.16)") (只有 3 个第一个参数;第三个参数`k`必须是整数) * [`numpy.tril()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.tril.html#numpy.tril "(in NumPy v1.16)") (第二个参数`k`必须是整数) * [`numpy.triu()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.triu.html#numpy.triu "(in NumPy v1.16)") (第二个参数`k`必须是整数) * [`numpy.unique()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html#numpy.unique "(in NumPy v1.16)") (只有第一个参数) * [`numpy.vander()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.vander.html#numpy.vander "(in NumPy v1.16)") * [`numpy.vstack()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html#numpy.vstack "(in NumPy v1.16)") * [`numpy.where()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html#numpy.where "(in NumPy v1.16)") * [`numpy.zeros()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros.html#numpy.zeros "(in NumPy v1.16)") (只有 2 个第一个参数) * [`numpy.zeros_like()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros_like.html#numpy.zeros_like "(in NumPy v1.16)") (只有 2 个第一个参数) 支持以下构造函数,包括数字输入(用于构造标量)或序列(用于构造数组): * `numpy.bool_` * `numpy.complex64` * `numpy.complex128` * `numpy.float32` * `numpy.float64` * `numpy.int8` * `numpy.int16` * `numpy.int32` * `numpy.int64` * `numpy.intc` * `numpy.intp` * `numpy.uint8` * `numpy.uint16` * `numpy.uint32` * `numpy.uint64` * `numpy.uintc` * `numpy.uintp` 支持以下机器参数类,所有纯数字属性: * [`numpy.iinfo`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.iinfo.html#numpy.iinfo "(in NumPy v1.16)") * [`numpy.finfo`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.finfo.html#numpy.finfo "(in NumPy v1.16)") (不支持`machar`属性) * [`numpy.MachAr`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.MachAr.html#numpy.MachAr "(in NumPy v1.16)") (没有构造函数的参数) ### 2.7.3.4。文字阵列 Python 和 Numba 都没有实际的数组文字,但你可以通过在嵌套元组上调用 [`numpy.array()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html#numpy.array "(in NumPy v1.16)") 来构造任意数组: ```py a = numpy.array(((a, b, c), (d, e, f))) ``` (Numba 尚不支持嵌套列表) ## 2.7.4。模块 ### 2.7.4.1。 `random` Numba 支持 [numpy.random](http://docs.scipy.org/doc/numpy/reference/routines.random.html) 模块中的顶级函数,但不允许您创建单独的 RandomState 实例。使用与[标准随机模块](pysupported.html#pysupported-random)相同的算法(因此适用相同的注释),但具有独立的内部状态:来自一个发电机的播种或抽取数字不会影响另一个。 支持以下功能。 #### 2.7.4.1.1。初始化 * [`numpy.random.seed()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.seed.html#numpy.random.seed "(in NumPy v1.16)") :仅带整数参数 #### 2.7.4.1.2。简单随机数据 * [`numpy.random.rand()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.rand.html#numpy.random.rand "(in NumPy v1.16)") * [`numpy.random.randint()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randint.html#numpy.random.randint "(in NumPy v1.16)") (只有前两个参数) * [`numpy.random.randn()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randn.html#numpy.random.randn "(in NumPy v1.16)") * [`numpy.random.random()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.random.html#numpy.random.random "(in NumPy v1.16)") * [`numpy.random.random_sample()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.random_sample.html#numpy.random.random_sample "(in NumPy v1.16)") * [`numpy.random.ranf()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.ranf.html#numpy.random.ranf "(in NumPy v1.16)") * [`numpy.random.sample()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.sample.html#numpy.random.sample "(in NumPy v1.16)") #### 2.7.4.1.3。排列 * [`numpy.random.choice()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.choice.html#numpy.random.choice "(in NumPy v1.16)") :不支持可选的 _p_ 参数(概率数组) * [`numpy.random.permutation()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.permutation.html#numpy.random.permutation "(in NumPy v1.16)") * [`numpy.random.shuffle()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.shuffle.html#numpy.random.shuffle "(in NumPy v1.16)") :序列参数必须是一维 Numpy 数组或缓冲区提供对象(例如 [`bytearray`](https://docs.python.org/3/library/stdtypes.html#bytearray "(in Python v3.7)") 或 [`array.array`](https://docs.python.org/3/library/array.html#array.array "(in Python v3.7)") ) #### 2.7.4.1.4。分布 警告 以下函数不支持 <cite>size</cite> 参数。 * [`numpy.random.beta()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.beta.html#numpy.random.beta "(in NumPy v1.16)") * [`numpy.random.binomial()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.binomial.html#numpy.random.binomial "(in NumPy v1.16)") * [`numpy.random.chisquare()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.chisquare.html#numpy.random.chisquare "(in NumPy v1.16)") * [`numpy.random.exponential()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.exponential.html#numpy.random.exponential "(in NumPy v1.16)") * [`numpy.random.f()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.f.html#numpy.random.f "(in NumPy v1.16)") * [`numpy.random.gamma()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.gamma.html#numpy.random.gamma "(in NumPy v1.16)") * [`numpy.random.geometric()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.geometric.html#numpy.random.geometric "(in NumPy v1.16)") * [`numpy.random.gumbel()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.gumbel.html#numpy.random.gumbel "(in NumPy v1.16)") * [`numpy.random.hypergeometric()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.hypergeometric.html#numpy.random.hypergeometric "(in NumPy v1.16)") * [`numpy.random.laplace()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.laplace.html#numpy.random.laplace "(in NumPy v1.16)") * [`numpy.random.logistic()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.logistic.html#numpy.random.logistic "(in NumPy v1.16)") * [`numpy.random.lognormal()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.lognormal.html#numpy.random.lognormal "(in NumPy v1.16)") * [`numpy.random.logseries()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.logseries.html#numpy.random.logseries "(in NumPy v1.16)") * [`numpy.random.multinomial()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.multinomial.html#numpy.random.multinomial "(in NumPy v1.16)") * [`numpy.random.negative_binomial()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.negative_binomial.html#numpy.random.negative_binomial "(in NumPy v1.16)") * [`numpy.random.normal()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html#numpy.random.normal "(in NumPy v1.16)") * [`numpy.random.pareto()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.pareto.html#numpy.random.pareto "(in NumPy v1.16)") * [`numpy.random.poisson()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.poisson.html#numpy.random.poisson "(in NumPy v1.16)") * [`numpy.random.power()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.power.html#numpy.random.power "(in NumPy v1.16)") * [`numpy.random.rayleigh()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.rayleigh.html#numpy.random.rayleigh "(in NumPy v1.16)") * [`numpy.random.standard_cauchy()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.standard_cauchy.html#numpy.random.standard_cauchy "(in NumPy v1.16)") * [`numpy.random.standard_exponential()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.standard_exponential.html#numpy.random.standard_exponential "(in NumPy v1.16)") * [`numpy.random.standard_gamma()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.standard_gamma.html#numpy.random.standard_gamma "(in NumPy v1.16)") * [`numpy.random.standard_normal()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.standard_normal.html#numpy.random.standard_normal "(in NumPy v1.16)") * [`numpy.random.standard_t()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.standard_t.html#numpy.random.standard_t "(in NumPy v1.16)") * [`numpy.random.triangular()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.triangular.html#numpy.random.triangular "(in NumPy v1.16)") * [`numpy.random.uniform()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.uniform.html#numpy.random.uniform "(in NumPy v1.16)") * [`numpy.random.vonmises()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.vonmises.html#numpy.random.vonmises "(in NumPy v1.16)") * [`numpy.random.wald()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.wald.html#numpy.random.wald "(in NumPy v1.16)") * [`numpy.random.weibull()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.weibull.html#numpy.random.weibull "(in NumPy v1.16)") * [`numpy.random.zipf()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.zipf.html#numpy.random.zipf "(in NumPy v1.16)") 注意 从非 Numba 代码(或从[对象模式](../glossary.html#term-object-mode)代码)调用 [`numpy.random.seed()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.seed.html#numpy.random.seed "(in NumPy v1.16)") 将为 Numpy 随机生成器播种,而不是 Numba 随机生成器。 注意 从版本 0.28.0 开始,发生器是线程安全的和叉安全的。每个线程和每个进程将产生独立的随机数流。 ### 2.7.4.2。 `stride_tricks` 支持`numpy.lib.stride_tricks`模块的以下功能: * [`as_strided()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.lib.stride_tricks.as_strided.html#numpy.lib.stride_tricks.as_strided "(in NumPy v1.16)") (_ 步长 _ 参数是必需的,不支持 _subok_ 参数) ## 2.7.5。标准 ufuncs Numba 的一个目标是让 Numba 理解 NumPy 中的所有[标准 ufuncs。当编译函数时找到支持的 ufunc 时,Numba 将 ufunc 映射到等效的本机代码。这允许在 Numba 代码中使用那些在](http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs) [nopython 模式](../glossary.html#term-nopython-mode)中编译的 ufunc。 ### 2.7.5.1。限制 现在,只有一些标准的 ufunc 工作在 [nopython 模式](../glossary.html#term-nopython-mode)。以下是 Numba 知道的不同标准 ufunc 的列表,其排序方式与 NumPy 文档中的排序方式相同。 ### 2.7.5.2。数学运算 | UFUNC | 模式 | | --- | --- | | 名称 | 对象模式 | nopython 模式 | | --- | --- | --- | | 加 | 是 | 是 | | 减去 | 是 | 是 | | 乘 | 是 | 是 | | 划分 | 是 | 是 | | logaddexp | 是 | 是 | | logaddexp2 | 是 | 是 | | true_divide | 是 | 是 | | floor_divide | 是 | 是 | | 负 | 是 | 是 | | 功率 | 是 | 是 | | 剩余 | 是 | 是 | | MOD | 是 | 是 | | FMOD | 是 | 是 | | ABS | 是 | 是 | | 绝对 | 是 | 是 | | 晶圆厂 | 是 | 是 | | RINT | 是 | 是 | | 标志 | 是 | 是 | | 连词 | 是 | 是 | | EXP | 是 | 是 | | EXP2 | 是 | 是 | | 日志 | 是 | 是 | | LOG2 | 是 | 是 | | LOG10 | 是 | 是 | | 的 expm1 | 是 | 是 | | log1p | 是 | 是 | | 开方 | 是 | 是 | | 广场 | 是 | 是 | | 倒数 | 是 | 是 | | 共轭 | 是 | 是 | ### 2.7.5.3。三角函数 | UFUNC | 模式 | | --- | --- | | 名称 | 对象模式 | nopython 模式 | | --- | --- | --- | | 罪 | 是 | 是 | | COS | 是 | 是 | | 黄褐色 | 是 | 是 | | 反正弦 | 是 | 是 | | ARCCOS | 是 | 是 | | 反正切 | 是 | 是 | | arctan2 | 是 | 是 | | hypot 将 | 是 | 是 | | 双曲正弦 | 是 | 是 | | 护身用手杖 | 是 | 是 | | 正切 | 是 | 是 | | arcsinh | 是 | 是 | | arccosh | 是 | 是 | | arctanh | 是 | 是 | | deg2rad | 是 | 是 | | rad2deg | 是 | 是 | | 度 | 是 | 是 | | 弧度 | 是 | 是 | ### 2.7.5.4。比特功能 | UFUNC | 模式 | | --- | --- | | 名称 | 对象模式 | nopython 模式 | | --- | --- | --- | | bitwise_and | 是 | 是 | | bitwise_or | 是 | 是 | | bitwise_xor | 是 | 是 | | bitwise_not | 是 | 是 | | 倒置 | 是 | 是 | | 左移 | 是 | 是 | | right_shift | 是 | 是 | ### 2.7.5.5。比较功能 | UFUNC | 模式 | | --- | --- | | 名称 | 对象模式 | nopython 模式 | | --- | --- | --- | | 更大 | 是 | 是 | | greater_equal | 是 | 是 | | 减 | 是 | 是 | | less_equal | 是 | 是 | | NOT_EQUAL | 是 | 是 | | 等于 | 是 | 是 | | logical_and | 是 | 是 | | 逻辑或 | 是 | 是 | | logical_xor | 是 | 是 | | logical_not | 是 | 是 | | 最大值 | 是 | 是 | | 最低限度 | 是 | 是 | | FMAX | 是 | 是 | | FMIN | 是 | 是 | ### 2.7.5.6。浮动功能 | UFUNC | 模式 | | --- | --- | | 名称 | 对象模式 | nopython 模式 | | --- | --- | --- | | ISFINITE | 是 | 是 | | isinf | 是 | 是 | | isnan | 是 | 是 | | signbit | 是 | 是 | | 复制符号 | 是 | 是 | | 函数 nextafter | 是 | 是 | | MODF | 是 | 没有 | | ldexp | 是的(*) | 是 | | frexp | 是 | 没有 | | 地板 | 是 | 是 | | 小区 | 是 | 是 | | TRUNC | 是 | 是 | | 间距 | 是 | 是 | (*)Windows 32 位不支持