这个NumPy发行版的特点是去掉了许多技术债务:对python2的支持被去掉了,许多反对意见已经过期,文档也得到了改进。随着Cython的bug修复和更好的可用性,随机模块的改进继续迅速进行。
此版本支持的Python版本是3.6-3.8。下游开发人员应该使用Cython>=0.29.16来支持python3.8和OpenBLAS>=3.7,以避免在Skylake架构上出现问题。
Python和C代码都取消了与Python版本<3.6(包括python2)的代码兼容性。将垫片插入 numpy.compat 将保留以支持第三方软件包,但在将来的版本中可能会弃用它们。请注意,1.19.x将 not 由于使用了f字符串,因此可以使用早期版本的Python进行编译。
numpy.compat
(gh-15233 ()
numpy.insert
numpy.delete
这结束了1.9中的一个弃用,其中 axis 参数已传递给对的调用 ~numpy.insert 和 ~numpy.delete 在0d数组中 axis 和 obj 参数和索引将被完全忽略。在这种情况下, insert(arr, "nonsense", 42, axis=0) 实际上会覆盖整个数组 delete(arr, "nonsense", axis=0) 将是 arr.copy()
axis
~numpy.insert
~numpy.delete
obj
insert(arr, "nonsense", 42, axis=0)
delete(arr, "nonsense", axis=0)
arr.copy()
现在过去了 axis 在0d数组中 ~numpy.AxisError .
~numpy.AxisError
(gh-15802 ()
本文总结了1.8和1.9中的弃用,其中 np.delete 将忽略索引序列中的负项和越界项。这与它通过单个索引时的行为不一致。
np.delete
现在界外项目抛出 IndexError ,从末尾开始索引负项。
IndexError
(gh-15804 ()
这总结了1.9中的一个弃用,其中允许非整数索引序列并将其转换为整数。现在传递非整指数序列 IndexError ,就像传递单个非整数标量时一样。
(gh-15805 ()
这是1.8中的一个弃用,其中 np.delete 将作为索引参数传递的布尔数组和标量强制转换为整数索引。现在的行为是将布尔数组视为掩码,并在布尔标量上引发错误。
(gh-15815 ()
numpy.random.Generator.dirichlet
生成具有小α值的Dirichlet分布的随机变量时,通过使用不同的算法修复了一个错误 max(alpha) < 0.1 . 由于这种变化,由 dirichlet 在这种情况下,将不同于以前的版本。
max(alpha) < 0.1
dirichlet
(gh-14924 ()
PyArray_ConvertToCommonType
混合标量和数组的推广 PyArray_ConvertToCommonType 已更改为与 np.result_type . 这意味着 (1000, np.array([1], dtype=np.uint8))) 现在将返回 uint16 数据类型。在大多数情况下,行为是不变的。请注意,通常不鼓励使用此C-API函数。这也修复了 np.choose 在这一点上要和其他人一样。
np.result_type
(1000, np.array([1], dtype=np.uint8)))
uint16
np.choose
(gh-14933 ()
fasttake和fastputmask插槽现在不再使用,必须始终设置为NULL。这不会导致行为的改变。但是,如果用户数据类型应该设置其中一个,则会给出DeprecationWarning。
(gh-14942 ()
np.ediff1d
to_end
to_begin
np.ediff1d 现在使用 "same_kind" 它的附加铸造规则 to_end 和 to_begin 论据。这可以确保类型安全,除非输入数组的整数类型小于 to_begin 或 to_end . 在极少数情况下,该行为将比1.16和1.17中的行为更加严格。这是解决浮点NaN问题所必需的。
"same_kind"
(gh-14981 ()
对象 len(obj) == 0 它实现了一个“类似数组”的接口,意思是一个对象实现 obj.__array__() , obj.__array_interface__ , obj.__array_struct__ ,或python缓冲区接口,它们也是序列(即Pandas对象),现在在转换为数组时将始终正确地保持其形状。如果这样一个物体的形状是 (0, 1) 以前,可以将其转换为形状数组 (0,) (在第一个0之后丢失所有维度)。
len(obj) == 0
obj.__array__()
obj.__array_interface__
obj.__array_struct__
(0, 1)
(0,)
(gh-14995 ()
multiarray.int_asbuffer
作为继续删除python2兼容性的一部分, multiarray.int_asbuffer 已删除。在python3上,它抛出了一个 NotImplementedError 内部未使用。在python3中,这种方法没有下游用例。
NotImplementedError
(gh-15229 ()
numpy.distutils.compat
此模块仅包含函数 get_exception() ,用作:
get_exception()
try: ... except Exception: e = get_exception()
它的目的是处理python2.6中引入的语法变化,从 except Exception, e: 到 except Exception as e: ,这意味着它只对支持python2.5及更高版本的代码库是必需的。
except Exception, e:
except Exception as e:
(gh-15255 ()
issubdtype
float
np.floating
numpy.issubdtype 从NumPy 1.14开始有一个未来警告,现在已经过期了。这意味着第二个参数既不是数据类型也不是NumPy标量类型(例如字符串或类似python的类型)的特定输入 int 或 float )现在将与传入一致 np.dtype(arg2).type . 这使得结果与预期一致,并在某些情况下导致错误的结果,而以前返回的结果为真。
numpy.issubdtype
int
np.dtype(arg2).type
(gh-15773 ()
round
输出 __round__ dunder方法和Python内置 round 已更改为Python int 与在Python上调用一致 float 不带参数调用时的对象。以前,它将返回 np.dtype 那是传进来的。
__round__
np.dtype
(gh-15840 ()
numpy.ndarray
strides=()
strides=None
前者已改为具有预期意义的设置 numpy.ndarray.strides 到 () 后者继续导致自动选择步幅。
numpy.ndarray.strides
()
(gh-15882 ()
简化了字符串的C级转换。这一变化还修复了字符串到datetime和timedelta的转换,使其行为正确(例如,类似于使用 string_arr.astype("M8") 而以前演员的表现 string_arr.astype(np.int_).astype("M8") . 这只会影响使用低级C-API对单个标量值进行手动强制转换(而不是完全数组强制转换)的代码,或者使用。 PyArray_GetCastFunc ,因此不应影响广大用户。
string_arr.astype("M8")
string_arr.astype(np.int_).astype("M8")
PyArray_GetCastFunc
(gh-16068 ()
SeedSequence
小种子(小于 2**96 )以前隐式地0填充到128位,即内部熵池的大小。生成时,在0填充之前连接生成键。因为第一个生成键是 (0,) ,小种子在产卵前会产生与第一次产卵相同的状态 SeedSequence . 现在,在连接spawn键之前,种子被显式地0填充到内部池大小。繁殖 SeedSequences 会产生不同于以前版本的结果。无遮篷 SeedSequences 仍然会产生相同的结果。
2**96
SeedSequences
(gh-16551 ()
dtype=object
调用 np.array([[1, [1, 2, 3]]) 将发行 DeprecationWarning 按照 NEP 34 . 用户应明确使用 dtype=object 以避免警告。
np.array([[1, [1, 2, 3]])
DeprecationWarning
(gh-15119 ()
shape=0
numpy.rec
0 被视为特例,并被化名为 None 在函数中:
0
None
numpy.core.records.fromarrays
numpy.core.records.fromrecords
numpy.core.records.fromstring
numpy.core.records.fromfile
将来, 0 将不会是特殊大小写,并将被视为数组长度一样,任何其他整数。
(gh-15217 ()
以下C-API函数可能未使用,已被弃用:
PyArray_GetArrayParamsFromObject
PyUFunc_GenericFunction
PyUFunc_SetUsesArraysAsData
在大多数情况下 PyArray_GetArrayParamsFromObject 应替换为转换为数组,而 PyUFunc_GenericFunction 可替换为 PyObject_Call (有关详细信息,请参阅文档)。
PyObject_Call
(gh-15427 ()
标量类型的超类,例如 np.integer , np.generic 或 np.inexact 当转换为dtype(或在dtype关键字参数中使用)时,将发出一个弃用警告。原因是 np.integer 转换为 np.int_ ,而它将代表 any 整数(例如 int8 , int16 例如, dtype=np.floating 当前与相同 dtype=np.float64 ,尽管也 np.float32 是的子类 np.floating .
np.integer
np.generic
np.inexact
np.int_
int8
int16
dtype=np.floating
dtype=np.float64
np.float32
(gh-15534 ()
np.complexfloating
输出 __round__ dunder方法和Python内置 round 在复杂标量上已被弃用。这不影响 np.round .
np.round
numpy.ndarray.tostring()
tobytes()
~numpy.ndarray.tobytes 从1.9版本就已经存在了,但是直到这个版本 ~numpy.ndarray.tostring 没有发出任何警告。发出警告的更改使NumPy与内置的一致 array.array 同名的方法。
~numpy.ndarray.tobytes
~numpy.ndarray.tostring
array.array
(gh-15867 ()
const
下面的函数现在接受 npy_intp :
npy_intp
PyArray_BroadcastToShape
PyArray_IntTupleFromIntp
PyArray_OverflowMultiplyList
以前,调用者必须舍弃常量才能调用这些函数。
(gh-15251 ()
UFuncGenericFunction 现在需要指向const的指针 dimension 和 strides 作为论据。这意味着内部循环可能不再修改 dimension 或 strides . 这种变化导致 incompatible-pointer-types 警告-强制用户忽略编译器警告或const限定自己的循环签名。
UFuncGenericFunction
dimension
strides
incompatible-pointer-types
(gh-15355 ()
numpy.frompyfunc
这允许 :attr:``numpy.ufunc.identity` 属性,这意味着它可以用于对 :meth:``numpy.ufunc.reduce '.
(gh-8255 ()
np.str_
np.str_ 数组总是存储为UCS4,因此相应的标量现在通过buffer接口公开了它,这意味着 memoryview(np.str_('test')) 现在工作。
memoryview(np.str_('test'))
(gh-15385 ()
subok
numpy.copy
一个新的夸格, subok ,已添加到 numpy.copy 允许用户切换 numpy.copy 关于数组子类。默认值为 False 这与 numpy.copy 对于以前的numpy版本。创建保留数组子类的副本 numpy.copy ,呼叫 np.copy(arr, subok=True) . 此添加更好地记录了 numpy.copy 不同于 numpy.ndarray.copy 默认情况下尊重数组子类的方法。
False
np.copy(arr, subok=True)
numpy.ndarray.copy
(gh-15685 ()
numpy.linalg.multi_dot
out
out 可以用来避免创建由 numpy.linalg.multidot .
numpy.linalg.multidot
(gh-15715 ()
keepdims
numpy.count_nonzero
参数 keepdims 已添加到 numpy.count_nonzero . 该参数的含义与在诸如 numpy.sum 或 numpy.mean .
numpy.sum
numpy.mean
(gh-15870 ()
equal_nan
numpy.array_equal
关键字参数 equal_nan 已添加到 numpy.array_equal . equal_nan 是一个布尔值,用于切换 nan 值在比较中被视为相等(默认值为 False ). 这与相关函数中使用的API相匹配,例如 numpy.isclose 和 numpy.allclose .
nan
numpy.isclose
numpy.allclose
(gh-16128 ()
替换 npy_cpu_supports 这是一个特定于gcc的机制,用于测试AVX对更通用功能的支持 npy_cpu_init 和 npy_cpu_have ,并通过 NPY_CPU_HAVE c宏以及python级别 __cpu_features__ 字典。
npy_cpu_supports
npy_cpu_init
npy_cpu_have
NPY_CPU_HAVE
__cpu_features__
(gh-13421 ()
在回退LAPACK库中的64位平台上使用64位整数大小,当系统未安装LAPACK时使用该库,允许它处理大型阵列的线性代数。
(gh-15218 ()
np.exp
np.float64
使用AVX512实现 np.exp 当输入为 np.float64 ,可以提高 np.exp 具有 np.float64 输入速度比以前快5-7倍。这个 _multiarray_umath.so 模块在linux64上增长了约63kb。
_multiarray_umath.so
(gh-15648 ()
在Linux上,NumPy以前添加了对madavise hugepages的支持,这可以提高超大阵列的性能。不幸的是,在较旧的内核版本上,这会导致性能退化,因此默认情况下,在版本4.6之前的内核上已经禁用了支持。要覆盖默认值,可以使用环境变量::
NUMPY_MADVISE_HUGEPAGE=0
或者将其设置为1以强制启用支持。请注意,只有将操作系统设置为使用madvise transparent hugepage时,这才有区别。
(gh-15769 ()
numpy.einsum
int64
当不再存在类型错误时引发 numpy.einsum 通过了一个NumPy int64 数组作为其下标列表。
(gh-16080 ()
np.logaddexp2.identity
-inf
UFUNC ~numpy.logaddexp2 现在的身份是 -inf ,允许在空序列上调用它。这与 ~numpy.logaddexp .
~numpy.logaddexp2
~numpy.logaddexp
(gh-16102 ()
__array__
从numpy0.4开始,代码中就出现了一个双参数变量的代码路径和测试 __array__(dtype=None, context=None) . 它在呼叫时被激活 ufunc(op) 或 ufunc.reduce(op) 如果 op.__array__ 存在的。然而,该变体没有记录在案,也不清楚其用途。它已被删除。
__array__(dtype=None, context=None)
ufunc(op)
ufunc.reduce(op)
op.__array__
(gh-15118 ()
numpy.random._bit_generator
numpy.random.bit_generator
为了暴露 numpy.random.BitGenerator 和 numpy.random.SeedSequence 给赛顿 _bitgenerator 模块现在公开为 numpy.random.bit_generator
numpy.random.BitGenerator
numpy.random.SeedSequence
_bitgenerator
pxd
c_distributions.pxd 提供对Cython中许多随机分布背后的c函数的访问,使其便于使用和扩展。
c_distributions.pxd
(gh-15463 ()
eigh
cholesky
numpy.random.multivariate_normal
以前,路过时 method='eigh' 或 method='cholesky' , numpy.random.multivariate_normal 从错误的分布中产生样本。现在已修复。
method='eigh'
method='cholesky'
(gh-15872 ()
MT19937.jumped
此修复程序将更改MT19937生成器生成的流。它不会影响使用 RandomState 或 MT19937 直接播种的。
RandomState
MT19937
MT19937跳转码的翻译包含一个反向循环顺序。 MT19937.jumped 匹配Makoto Matsumoto最初实现的Horner和滑动窗口跳转方法。
(gh-16153 ()