NumPy 1.18.0发行说明

除了常见的bug修复之外,这个NumPy版本还清理并记录了新的随机C-API,终止了大量旧的不赞成意见,并改进了文档的外观。支持的Python版本是3.5-3.8。这是最后一个支持python3.5的NumPy发行版系列。

下游开发人员应该使用Cython>=0.29.14来支持python3.8和OpenBLAS>=3.7,以避免在Skylake架构上出现问题。

集锦

  • 的C-API numpy.random 已定义并记录。

  • 用于链接64位BLAS和LAPACK库的基本基础设施。

  • 许多文档改进。

新功能

多变量超几何分布 numpy.random

方法 multivariate_hypergeometric has been added to the class numpy.random.Generator. This method generates random variates from the multivariate hypergeometric probability distribution. (gh-13794

贬抑

np.fromfilenp.fromstring 错误数据将导致错误

在未来的numpy版本中,函数 np.fromfile and np.fromstring will throw an error when parsing bad data. This will now give a DeprecationWarning where previously partial or even invalid data was silently returned. This deprecation also affects the C defined functions PyArray_FromString and PyArray_FromFile (gh-13605

不推荐使用非标量数组作为中的填充值 ma.fill_value

设置一个 MaskedArray.fill_value to a non-scalar array is deprecated since the logic to broadcast the fill value to the array is fragile, especially when slicing. (gh-13698

贬低 PyArray_As1DPyArray_As2D

PyArray_As1D, PyArray_As2D are deprecated, use PyArray_AsCArray instead (gh-14036

贬低 np.alen

np.alen was deprecated. Use len instead. (gh-14181

贬低财务职能

按照 NEP-32, the financial functions fv ipmt, irr, mirr, nper, npv, pmt, ppmt, pv and rate are deprecated, and will be removed from NumPy 1.20.The replacement for these functions is the Python package numpy-financial. (gh-14720

这个 axis 参数 numpy.ma.mask_colsnumpy.ma.mask_row 被贬低

这个论点总是被忽视。 (gh-14996 ()

过期的折旧

  • PyArray_As1D and PyArray_As2D have been removed in favor of PyArray_AsCArray (gh-14036

  • np.rank has been removed. This was deprecated in NumPy 1.10 and has been replaced by np.ndim. (gh-14039

  • 反对 expand_dims out-of-range axes in 1.13.0 has expired. (gh-14051

  • PyArray_FromDimsAndDataAndDescr and PyArray_FromDims have been removed (they will always raise an error). Use PyArray_NewFromDescr and PyArray_SimpleNew instead. (gh-14100

  • numeric.loads, numeric.load, np.ma.dump, np.ma.dumps, np.ma.load, np.ma.loads are removed, use pickle methods instead (gh-14256

  • arrayprint.FloatFormatarrayprint.LongFloatFormat 已删除,请使用 FloatingFormat 相反

  • arrayprint.ComplexFormatarrayprint.LongComplexFormat 已删除,请使用 ComplexFloatingFormat 相反

  • arrayprint.StructureFormat has been removed, use StructureVoidFormat instead (gh-14259

  • np.testing.rand has been removed. This was deprecated in NumPy 1.11 and has been replaced by np.random.rand. (gh-14325

  • 等级 SafeEval in numpy/lib/utils.py has been removed. This was deprecated in NumPy 1.10. Use np.safe_eval instead. (gh-14335

  • 删除中不推荐使用的对布尔值和空条件列表的支持 np.select (gh-14583

  • 数组顺序只接受“C”、“F”、“A”和“K”。NUMPY1.11中否决了更多的允许选项。 (gh-14596 ()

  • np.L空间参数 num must be an integer. Deprecated in NumPy 1.12. (gh-14620

  • 具有多个输出的UFuncs必须为 out kwarg. This finishes a deprecation started in NumPy 1.10. (gh-14682

档案 numpy/testing/decorators.py, numpy/testing/noseclasses.py and numpy/testing/nosetester.py have been removed. They were never meant to be public (all relevant objects are present in the numpy.testing namespace), and importing them has given a deprecation warning since NumPy 1.15.0 (gh-14567

兼容性说明

numpy.lib.recfunctions.drop_fields 不能再返回“无”

如果 drop_fields 用于删除所有字段,以前该数组将被完全丢弃且不返回任何字段。现在它返回一个与输入形状相同的数组,但没有字段。旧的行为可以保留为:

dropped_arr = drop_fields(arr, ['a', 'b'])
if dropped_arr.dtype.names == ():
    dropped_arr = None

将空重新排列转换为无 (gh-14510 ()

numpy.argmin/argmax/min/max 收益率 NaT 如果它存在于数组中

numpy.argmin, numpy.argmax, numpy.min, and numpy.max will return NaT if it exists in the array. (gh-14717

np.can_cast(np.uint64, np.timedelta64, casting='safe') is now False

以前这是 True -然而,这与 uint64 不能安全地浇铸到 int64 ,并导致奇怪的类型分辨率。

如果这影响了你的代码,请强制转换 uint64 to int64 first. (gh-14718

已更改的随机变量流 numpy.random.Generator.integers

里面有个窃听器 numpy.random.Generator.integers that caused biased sampling of 8 and 16 bit integer types. Fixing that bug has changed the output stream from what it was in previous releases. (gh-14777

为添加更多ufunc循环 datetime64timedelta64

np.datetime('NaT') should behave more like float('Nan'). Add needed infrastructure so np.isinf(a) and np.isnan(a) will run on datetime64 and timedelta64 dtypes. Also added specific loops for numpy.fmin and numpy.fmax that mask NaT. This may require adjustment to user- facing code. Specifically, code that either disallowed the calls to numpy.isinf or numpy.isnan or checked that they raised an exception will require adaptation, and code that mistakenly called numpy.fmax and numpy.fmin instead of numpy.maximum or numpy.minimum respectively will require adjustment. This also affects numpy.nanmax and numpy.nanmin. (gh-14841

已将模块移入 numpy.random

作为API清理的一部分,中的子模块 numpy.random bit_generator, philox, pcg64, sfc64, ``common, generator, and bounded_integers were moved to _bit_generator, _philox, _pcg64, _sfc64, ``_common, _generator, and _bounded_integers respectively to indicate that they are not part of the public interface. (gh-14608

C API更改

PyDataType_ISUNSIZED(descr) 对于结构化数据类型,现在返回False

以前,对于itemsize为0的任何数据类型,它都返回True,但现在对于itemsize为0的非灵活数据类型,它返回false, np.dtype([]). (gh-14393

新特点

添加我们自己的 *.pxd cython导入文件

增加了一个 numpy/__init__.pxd file. It will be used for cimport numpy (gh-12284

一组轴现在可以输入到 expand_dims

这个 numpy.expand_dims axis keyword can now accept a tuple of axes. Previously, axis was required to be an integer. (gh-14051

支持64位OpenBLAS

增加了对64位(ILP64)OpenBLAS的支持。看到了吗 site.cfg.example for details. (gh-15012

添加 --f2cmap F2PY选项

允许指定要从中加载Fortran-to-C类型映射自定义项的文件。 (gh-15113 ()

改进

相同大小的不同C数字类型具有唯一的名称

在任何给定的平台上 np.intcnp.int_np.longlong 以前通过他们的 repr ,尽管 dtype 具有不同的特性。类似的问题也存在于这些类型的无符号对应项上,在某些平台上也存在 np.doublenp.longdouble

这些类型现在总是打印一个独特的 __name__. (gh-10151

argwhere 现在在0d数组上生成一致的结果

在N-d阵列上, numpy.argwhere now always produces an array of shape (n_non_zero, arr.ndim), even when arr.ndim == 0. Previously, the last axis would have a dimension of 1 in this case. (gh-13610

添加 axis 的参数 random.permutationrandom.shuffle

以前 random.permutation and random.shuffle functions can only shuffle an array along the first axis; they now have a new argument axis which allows shuffle along a specified axis. (gh-13829

method keyword argument for np.random.multivariate_normal

A method keyword argument is now available for np.random.multivariate_normal with possible values {{'svd', 'eigh', 'cholesky'}}. To use it, write np.random.multivariate_normal(..., method=<method>). (gh-14197

添加复数支持 numpy.fromstring

现在 numpy.fromstring can read complex numbers. (gh-14227

numpy.unique 有一致的轴顺序 axis 不是没有

使用 moveaxis instead of swapaxes in numpy.unique, so that the ordering of axes except the axis in arguments will not be broken. (gh-14255

numpy.matmul 带布尔值的输出现在转换为布尔值

调用 numpy.matmul where the output is a boolean array would fill the array with uint8 equivalents of the result, rather than 0/1. Now it forces the output to 0 or 1 (NPY_TRUE or NPY_FALSE). (gh-14464

numpy.random.randint produced incorrect value when the range was 2**32

在1.17.0中引入的实现在确定是否使用32位路径或完整的64位路径时进行了错误的检查,该路径错误地重定向了随机整数生成的高低范围 2**32 to the 64-bit generator. (gh-14501

添加复数支持 numpy.fromfile

现在 numpy.fromfile can read complex numbers. (gh-14730

std=c99 added if compiler is named gcc

GCC版本5之前需要 -std=c99 command line argument. Newer compilers automatically turn on C99 mode. The compiler setup code will automatically add the code if the compiler name has gcc in it. (gh-14771

变化

NaT 现在排序到数组的末尾

NaT is now effectively treated as the largest integer for sorting purposes, so that it sorts to the end of arrays. This change is for consistency with NaN sorting behavior. (gh-12658 ) (gh-15068 ()

不正确 threshold 在里面 np.set_printoptions 加薪 TypeErrorValueError

以前的错误 threshold raised ValueError; it now raises TypeError for non-numeric types and ValueError for nan values. (gh-13899

使用元数据保存数据类型时发出警告

A UserWarning will be emitted when saving an array via numpy.save with metadata. Saving such an array may not preserve metadata, and if metadata is preserved, loading it will cause a ValueError. This shortcoming in save and load will be addressed in a future release. (gh-14142

numpy.distutils LDFLAGS和类似文件的追加行为已更改

numpy.distutils has always overridden rather than appended to LDFLAGS and other similar such environment variables for compiling Fortran extensions. Now the default behavior has changed to appending - which is the expected behavior in most situations. To preserve the old (overwriting) behavior, set the NPY_DISTUTILS_APPEND_FLAGS environment variable to 0. This applies to: LDFLAGS, F77FLAGS, F90FLAGS, FREEFLAGS, FOPT, FDEBUG, and FFLAGS. NumPy 1.16 and 1.17 gave build warnings in situations where this change in behavior would have affected the compile flags used. (gh-14248

去除 numpy.random.entropy 没有贬损

numpy.random.entropy was added to the numpy.random namespace in 1.17.0. It was meant to be a private c-extension module, but was exposed as public. It has been replaced by numpy.random.SeedSequence so the module was completely removed. (gh-14498

将选项添加到静默构建配置和使用 -Werror

添加了两个新的配置选项。在 build_src 子命令,作为配置NumPy的一部分 _numpyconfig.hconfig.h 是通过探测对各种运行时函数和例程的支持而创建的。以前,在这个阶段非常详细的编译器输出会模糊更重要的信息。默认情况下,输出是静音的。跑步 runtests.py --debug-info 将添加 --verbose-cfgbuild_src 子命令将恢复以前的行为。

添加 CFLAGS=-Werror 将警告变为错误会在配置过程中触发错误。现在 runtests.py --warn-error 将添加 --warn-errorbuild 子命令,它将渗透到 build_extbuild_lib 子命令。这将向这些阶段添加编译器标志,并在实际构建NumPy本身时将编译器警告变成错误,从而避免 build_src 子命令编译器调用。

(gh-14527 () (gh-14518 ()