(n,)
括号中跟着逗号的数字表示一个具有一个元素的元组。尾随逗号将一个元素元组与括号n
区分开。
-1
在维度入口中,指示 NumPy 选择长度,以保持数组元素总数不变。
>>> np.arange(12).reshape(4, -1).shape
(4, 3)
在索引中,任何负值表示从右边进行索引。
…
一个省略号
。
当索引数组时,缺失的轴简称为全切片。
>>> a = np.arange(24).reshape(2,3,4)
>>> a[...].shape
(2, 3, 4)
>>> a[...,0].shape
(2, 3)
>>> a[0,...].shape
(3, 4)
>>> a[0,...,0].shape
(3,)
它最多可以使用一次;a[...,0,...]
会引发一个IndexError
。
在打印输出中,NumPy 用...
替代大数组的中间元素。要查看整个数组,使用numpy.printoptions
:
Python 的切片操作符。在 ndarrays 中,切片可以应用于每个轴:
>>> a = np.arange(24).reshape(2,3,4)
>>> a
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
>>> a[1:,-2:,:-1]
array([[[16, 17, 18],
[20, 21, 22]]])
尾部切片可以省略:
>>> a[1] == a[1,:,:]
array([[ True, True, True, True],
[ True, True, True, True],
[ True, True, True, True]])
与 Python 不同,NumPy 中切片创建一个视图而不是副本。
详见组合高级和基本索引。
<
在 dtype 声明中,表示数据为小端(右边是大括号)。
>>> dt = np.dtype('<f') # little-endian single-precision float
在 dtype 声明中,表示数据为大端(左边是大括号)。
>>> dt = np.dtype('>H') # big-endian unsigned short
高级索引
而不是使用标量或切片作为索引,一个轴可以用数组作为索引,提供精细选择。这被称为高级索引或“花式索引”。
沿轴
数组a
的操作沿轴 n的行为就好像它的参数是数组a
的切片数组,每个切片在轴n上具有连续索引。
例如,如果a
是一个 3 x N数组,沿轴 0 的操作表现得好像它的参数是包含每行切片的数组:
>>> np.array((a[0,:], a[1,:], a[2,:]))
具体起见,我们可以选择操作为数组反转函数numpy.flip
,它接受一个axis
参数。我们构造一个 3 x 4 数组a
:
>>> a = np.arange(12).reshape(3,4)
>>> a
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
沿轴 0(行轴)翻转得到
>>> np.flip(a,axis=0)
array([[ 8, 9, 10, 11],
[ 4, 5, 6, 7],
[ 0, 1, 2, 3]])
回想沿轴的定义,沿轴 0 翻转是将其参数视为
>>> np.array((a[0,:], a[1,:], a[2,:]))
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
而np.flip(a,axis=0)
的结果是翻转切片:
>>> np.array((a[2,:],a[1,:],a[0,:]))
array([[ 8, 9, 10, 11],
[ 4, 5, 6, 7],
[ 0, 1, 2, 3]])
数组
在 NumPy 文档中与 ndarray 同义使用。
array_like
任何可以解释为 ndarray 的标量或序列。除了 ndarrays 和标量,此类别还包括列表(可能嵌套并具有不同的元素类型)和元组。由 numpy.array 接受的任何参数都是 array_like。
>>> a = np.array([[1, 2.0], [0, 0], (1+1j, 3.)])
>>> a
array([[1.+0.j, 2.+0.j],
[0.+0.j, 0.+0.j],
[1.+1.j, 3.+0.j]])
数组标量
数组标量是类型/类 float32,float64 等的实例。为了处理操作数的统一性,NumPy 将标量视为零维数组。相比之下,零维数组是包含精确一个值的 ndarray 实例。
轴
数组维度的另一个术语。轴从左到右编号;轴 0 是形状元组中的第一个元素。
在二维矢量中,轴 0 的元素是行,轴 1 的元素是列。
在更高的维度中,情况就不一样了。NumPy 将更高维度的矢量打印为行列建造块的复制,就像这个三维矢量一样:
>>> a = np.arange(12).reshape(2,2,3)
>>> a
array([[[ 0, 1, 2],
[ 3, 4, 5]],
[[ 6, 7, 8],
[ 9, 10, 11]]])
a
被描述为一个其元素为 2x3 矢量的两元素数组。从这个角度来看,行和列分别是任何形状中的最终两个轴。
这个规则可以帮助你预测矢量将如何打印,反过来也可以帮助你找到任何打印元素的索引。例如,在这个例子中,8 的最后两个值的索引必须是 0 和 2。由于 8 出现在两个 2x3 中的第二个中,第一个索引必须是 1:
>>> a[1,0,2]
8
在打印矢量时,计算维度的一个方便方法是在开括号后计数[
符号。这在区分例如(1,2,3)形状和(2,3)形状时非常有用:
>>> a = np.arange(6).reshape(2,3)
>>> a.ndim
2
>>> a
array([[0, 1, 2],
[3, 4, 5]])
>>> a = np.arange(6).reshape(1,2,3)
>>> a.ndim
3
>>> a
array([[[0, 1, 2],
[3, 4, 5]]])
.base
如果一个数组没有拥有它的内存,那么它的基础属性会返回数组正在引用的对象的内存。该对象可能正在引用另一个对象的内存,因此拥有对象可能是a.base.base.base...
。一些作家错误地声称测试base
决定数组是否是视图。有关正确的方法,请参阅numpy.shares_memory
。
大端
请参见字节序。
BLAS
广播
广播是 NumPy 处理不同大小的 ndarray 的能力,就好像它们都是相同大小一样。
它允许优雅的做-我-知道什么的行为,在这种情况下,将标量添加到向量会将标量值添加到每个元素。
>>> a = np.arange(3)
>>> a
array([0, 1, 2])
>>> a + [3, 3, 3]
array([3, 4, 5])
>>> a + 3
array([3, 4, 5])
通常,向量操作数必须全部具有相同的大小,因为 NumPy 逐元素工作——例如,c = a * b
是
c[0,0,0] = a[0,0,0] * b[0,0,0]
c[0,0,1] = a[0,0,1] * b[0,0,1]
...
但在某些有用的情况下,NumPy 可以沿着“缺失”的轴或“太短”的维度复制数据,使形状匹配。复制不会占用内存或时间。详情请参见广播。
C 顺序
与行主导相同。
列主导
查看行优先和列优先顺序。
连续的
如果数组是连续的,则:
有两种类型的适当连续的 NumPy 数组:
对于一维数组,这些概念是相同的。
例如,2x2 数组A
如果其元素按以下顺序存储在内存中,则为 Fortran 连续:
A[0,0] A[1,0] A[0,1] A[1,1]
且如果顺序如下,则为 C 连续:
A[0,0] A[0,1] A[1,0] A[1,1]
要测试数组是否为 C 连续,请使用 NumPy 数组的.flags.c_contiguous
属性。要测试 Fortran 连续性,请使用.flags.f_contiguous
属性。
拷贝
查看视图。
维度
查看轴。
数据类型
描述 ndarray 中(类型相同的)元素的数据类型。它可以更改以重新解释数组内容。详情请参见数据类型对象(dtype)。
精细索引
高级索引的另一个术语。
字段
在结构化数据类型中,每个子类型称为字段。字段具有名称(字符串)、类型(任何有效的 dtype)和可选的标题。请参见数据类型对象(dtype)。
Fortran 顺序
与列主导相同。
展平
查看拉伸。
同质的
同质数组的所有元素具有相同类型。与 Python 列表相反,ndarrays 是同质的。类型可能很复杂,如结构化数组,但所有元素都具有该类型。
NumPy 的对象数组,其中包含指向 Python 对象的引用,起到异构数组的作用。
数据项大小
dtype 元素的字节大小。
小端
查看字节顺序。
掩码
用于选??仅对某些元素进行操作的布尔数组:
>>> x = np.arange(5)
>>> x
array([0, 1, 2, 3, 4])
>>> mask = (x > 2)
>>> mask
array([False, False, False, True, True])
>>> x[mask] = -1
>>> x
array([ 0, 1, 2, -1, -1])
蒙版数组
坏的或缺失的数据可以通过将其放入蒙版数组中,该数组具有指示无效条目的内部布尔数组来干净地忽略。对于带有蒙版数组的操作会忽略这些条目。
>>> a = np.ma.masked_array([np.nan, 2, np.nan], [True, False, True])
>>> a
masked_array(data=[--, 2.0, --],
mask=[ True, False, True],
fill_value=1e+20)
>>> a + [1, 2, 3]
masked_array(data=[--, 4.0, --],
mask=[ True, False, True],
fill_value=1e+20)
详情请参见蒙版数组。
矩阵
NumPy 的二维矩阵类不应再使用;请使用常规 ndarrays。
ndarray
NumPy 的基本结构。
对象数组
一个其数据类型为object
的数组;即,它包含对 Python 对象的引用。对数组进行索引解引用 Python 对象,因此与其他 ndarrays 不同,对象数组具有能够保存异构对象的能力。
ravel
numpy.ravel 和 numpy.flatten 都会将 ndarray 展平。如果可能,ravel
会返回视图;flatten
总是返回副本。
展平将多维数组折叠为单个维度;如何完成此操作的详细信息(例如,a[n+1]
应该是下一行还是下一列)是参数。
记录数组
允许以属性样式(a.field
)访问的一个结构化数组,除了a['field']
。详情请参见 numpy.recarray.
行主序
参见行主序和列主序。NumPy 默认以行主序创建数组。
标量
在 NumPy 中,通常是数组标量的同义词。
形状
显示 ndarray 每个维度的长度的元组。元组本身的长度即为维度的数量(numpy.ndim)。元组元素的乘积即为数组中的元素数量。详情请参见 numpy.ndarray.shape。
步幅
物理内存是一维的;步幅提供了一种将给定索引映射到内存地址的机制。对于 N 维数组,其strides
属性是一个 N 元素元组;从索引i
向轴n
上的索引i+1
前进意味着在地址上添加a.strides[n]
个字节。
步幅会自动从数组的 dtype 和形状中计算,但也可以直接使用 as_strided 指定。
详情请参见 numpy.ndarray.strides。
要了解步进是如何支撑 NumPy 视图的强大功能,请参见NumPy 数组:高效数值计算的结构。
结构化数组
其 dtype 为结构化数据类型的数组。
结构化数据类型
用户可以创建包含其他数组和数据类型的任意复杂的 dtype,这些复合 dtype 被称为结构化数据类型。
子数组
嵌套在结构化数据类型中的数组,如此处的b
:
>>> dt = np.dtype([('a', np.int32), ('b', np.float32, (3,))])
>>> np.zeros(3, dtype=dt)
array([(0, [0., 0., 0.]), (0, [0., 0., 0.]), (0, [0., 0., 0.])],
dtype=[('a', '<i4'), ('b', '<f4', (3,))])
子数组数据类型
表现得像一个 ndarray 的结构化数据类型的元素。
标题
结构化数据类型中字段名称的别名。
类型
在 NumPy 中,通常是 dtype 的同义词。对于更一般的 Python 含义,请参见此处。
ufunc
NumPy 的快速逐元素计算(向量化)可以选择应用哪个函数。该函数的通用术语是ufunc
,缩写为universal function
。NumPy 例程具有内置的 ufunc,但用户也可以编写自己的。
向量化
NumPy 把数组处理交给了 C 语言,在那里循环和计算比在 Python 中快得多。为了利用这一点,使用 NumPy 的程序员取消了 Python 循环,而是使用数组对数组操作。向量化 既可以指 C 的卸载,也可以指结构化 NumPy 代码以利用它。
视图
不触及底层数据,NumPy 可使一个数组看起来改变其数据类型和形状。
以此方式创建的数组是一个视图,而且 NumPy 经常利用使用视图而不是创建新数组来获得性能优势。
潜在的缺点是对视图的写入也可能改变原始数组。如果这是一个问题,NumPy 需要创建一个物理上不同的数组 - 一个copy
.
一些 NumPy 例程总是返回视图,一些总是返回副本,有些可能返回其中之一,对于一些情况可以指定选择。管理视图和副本的责任落在程序员身上。numpy.shares_memory
可以检查b
是否为a
的视图,但精确答案并非总是可行,就像文档页面所解释的那样。
>>> x = np.arange(5)
>>> x
array([0, 1, 2, 3, 4])
>>> y = x[::2]
>>> y
array([0, 2, 4])
>>> x[0] = 3 # changing x changes y as well, since y is a view on x
>>> y
array([3, 2, 4])
numpy.array_api
中的数组 API v2022.12 支持
f2py
的meson
后端支持
f2py
的bind(c)
支持
f2py
的iso_c_binding
支持mode=wrap
时,np.pad
使用严格的原始数据倍数进行填充
long_t
和ulong_t
ufunc
的axes
参数错误消息和类型已更改
where
,则支持定义__array_ufunc__
的类数组可以覆盖ufunc
np.einsum
现在接受具有 object
数据类型的数组
NPY_ENABLE_CPU_FEATURES
环境变量
np.exceptions
命名空间
np.linalg
函数返回 NamedTuples
np.char
中的字符串函数与 NEP 42 自定义 dtype 兼容
NDArrayOperatorsMixin
指定它没有 __slots__
DTypePromotionError
np.ma.diff
不保留掩码的问题。
numpy.logspace
现在支持非标量 base
参数
np.ma.dot()
现在支持非 2D 数组
np.dtypes
中公开了 DType 类
numpy.lib.recfunctions.structured_to_unstructured
在更多情况下返回视图
np.argsort
更快了
np.sort
更快了
__array_function__
机制的速度提升](release/1.25.0-notes.html#array-function-machinery-is-now-much-faster)
ufunc.at
的速度可以提升很多](release/1.25.0-notes.html#ufunc-at-can-be-much-faster)
NpzFile
上的成员测试更快](release/1.25.0-notes.html#faster-membership-test-on-npzfile)
np.r_[]
和 np.c_[]
的某些标量值](release/1.25.0-notes.html#np-r-and-np-c-with-certain-scalar-values)
fastCopyAndTranspose
和 PyArray_CopyAndTranspose
](release/1.24.0-notes.html#deprecate-fastcopyandtranspose-and-pyarray-copyandtranspose)
msort
](release/1.24.0-notes.html#deprecate-msort)
np.str0
和类似对象现在弃用](release/1.24.0-notes.html#np-str0-and-similar-are-now-deprecated)
array.fill(scalar)
的行为可能略有不同](release/1.24.0-notes.html#array-fill-scalar-may-behave-slightly-different)
BufferError
引发 DLPack 导出错误
symbol
属性](release/1.24.0-notes.html#new-attribute-symbol-added-to-polynomial-classes)
character
字符串的 F2PY 支持](release/1.24.0-notes.html#f2py-support-for-fortran-character-strings)
np.show_runtime
](release/1.24.0-notes.html#new-function-np-show-runtime)
testing.assert_array_equal
的 strict
选项](release/1.24.0-notes.html#strict-option-for-testing-assert-array-equal)
np.unique
的新参数equal_nan
numpy.stack
的casting
和dtype
关键字参数
numpy.vstack
的casting
和dtype
关键字参数
numpy.hstack
的casting
和dtype
关键字参数
np.void
现在有一个dtype
参数
arange()
现在明确在 dtype 为 str 时失败
numpy.typing
协议现在可以在运行时检查
np.isin
和np.in1d
的更快版本
masked_invalid
现在就地修改掩码
nditer
/NpyIter
允许为所有操作数进行分配
genfromtxt
新增参数ndmin
np.loadtxt
现在支持引号字符和单个转换函数
average
的keepdims
参数
np.unique
新增参数equal_nan
np.linalg.norm
现在保留了浮点输入类型,即使对于标量结果
NPY_RELAXED_STRIDES_CHECKING
已被移除
np.loadtxt
已经接收到一些更改
ndarray.__array_finalize__
现在可调用
np.fromiter
现在接受对象和子数组
np.kron
现在保留子类信息
np.loadtxt
np.where
np.kron
loads
,ndfromtxt
和mafromtxt
的过时弃用已移除
kth
值传递给(arg-)partition 已被弃用
np.MachAr
类已被弃用
numpy.vectorize
函数现在产生与基础函数相同的输出类
PCG64DSXM
和PCG64
中纠正了advance
c_intp
精度
keepdims
可选参数添加到numpy.argmin
,numpy.argmax
bit_count
用于计算整数中 1 位的数量
ndim
和axis
属性已添加到numpy.AxisError
windows/arm64
目标的初步支持
.clang-format
文件
is_integer
现在适用于numpy.floating
和numpy.integer
ndarray
, dtype
和number
现在可以在运行时进行下标索引
ctypeslib.load_library
现在可以接受任何类路径对象
finfo
添加smallest_normal
和smallest_subnormal
属性
numpy.linalg.qr
接受堆叠矩阵作为输入
numpy.fromregex
现在接受os.PathLike
的实现
quantile
和percentile
添加新方法
nan<x>
函数添加了缺失参数
PCG64DXSM
BitGenerator
.dtype
属性必须返回dtype
numpy.convolve
和numpy.correlate
的不精确匹配已弃用
np.typeDict
已正式弃用
ndarray.ctypes
方法
PolyBase
和未使用的PolyError
和PolyDomainError
__array_ufunc__
参数验证
__array_ufunc__
和额外的位置参数
Generator.uniform
中验证输入数值
/usr/include
从默认包含路径中移除
dtype=...
的比较的更改
dtype
和 signature
参数的更改
signature=...
和 dtype=
泛化以及casting
ufunc->type_resolver
和 “type tuple”numpy.number
精度添加了一个 mypy 插件
numpy.number
子类
min_digits
参数
ndarray
添加了一个运行时可订阅的别名
numpy.unwrap
的任意 period
选项
np.unique
现在返回单个 NaN
Generator.rayleigh
和 Generator.geometric
性能改进
np.save
和np.load
在小数组上的性能
numpy.piecewise
的输出类现在与输入类匹配
random.Generator
类有一个新的 permuted
函数。
sliding_window_view
为 numpy 数组提供了滑动窗口视图(release/1.20.0-notes.html#sliding-window-view-provides-a-sliding-window-view-for-numpy-arrays)
numpy.broadcast_shapes
是一???新的用户可见函数(release/1.20.0-notes.html#numpy-broadcast-shapes-is-a-new-user-facing-function)
np.int
等内置类型的别名(release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated)
shape=None
传递给具有非可选形状参数的函数已被弃用(release/1.20.0-notes.html#passing-shape-none-to-functions-with-a-non-optional-shape-argument-is-deprecated)
mode
和searchside
的不精确匹配已被弃用(release/1.20.0-notes.html#inexact-matches-for-mode-and-searchside-are-deprecated)
outer
和 ufunc.outer
对矩阵已弃用(release/1.20.0-notes.html#outer-and-ufunc-outer-deprecated-for-matrix)
ndindex
的 ndincr
方法已被弃用(release/1.20.0-notes.html#the-ndincr-method-of-ndindex-is-deprecated)
__len__
和__getitem__
的 ArrayLike 对象(release/1.20.0-notes.html#arraylike-objects-which-do-not-define-len-and-getitem)
isinstance(dtype, np.dtype)
而不是 type(dtype) is not np.dtype
。
axis=None
的情况下使用相同种类转换融合。
numpy.broadcast_arrays
的结果将导出只读缓冲区。
operator.concat
函数现在对数组参数引发 TypeError。
nickname
属性。
float->timedelta
和 uint64->timedelta
提升将引发 TypeError。
numpy.genfromtxt
现在正确解包结构化数组。
mgrid
、r_
等对非默认精度输入一直返回正确输出。
IndexError
。
__array_interface__["data"]
元组的第一个元素必须是整数。
poly1d
尊重所有零参数的数据类型。
np.array
中发现空数据类型。
PyArray_DescrCheck
宏被修改
np.ndarray
和 np.void_
的大小发生了变化
numpy.all
和 numpy.any
函数的 where
关键字参数
numpy
函数 mean
、std
、var
的 where
关键字参数
numpy.fft
函数的 norm=backward
、forward
关键字选项
numpy.typing
__f2py_numpy_version__
属性。
mypy
测试
cov
和 corrcoef
的 dtype
选项
__str__
)
repr
更易读
concatenate
函数支持提供输出的数据类型
numpy.core.records.fromfile
现在支持类文件对象
divmod(1., 0.)
和相关函数的行为
np.linspace
在整数上使用 floor](release/1.20.0-notes.html#np-linspace-on-integers-now-uses-floor)
numpy.insert
和 numpy.delete
不再可以在 0 维数组上通过轴传递](release/1.19.0-notes.html#numpy-insert-and-numpy-delete-can-no-longer-be-passed-an-axis-on-0d-arrays)
numpy.delete
不再忽略超出范围的索引](release/1.19.0-notes.html#numpy-delete-no-longer-ignores-out-of-bounds-indices)
numpy.insert
和 numpy.delete
不再接受非整数索引](release/1.19.0-notes.html#numpy-insert-and-numpy-delete-no-longer-accept-non-integral-indices)
numpy.delete
不再将布尔索引强制转换为整数](release/1.19.0-notes.html#numpy-delete-no-longer-casts-boolean-indices-to-integers)
numpy.random.Generator.dirichlet
更改随机变量流
PyArray_ConvertToCommonType
中的标量提升
np.ediff1d
在 to_end
和 to_begin
上的类型转换行为
multiarray.int_asbuffer
numpy.distutils.compat
issubdtype
不再将 float
解释为 np.floating
round
的输出以与 Python 一致
numpy.ndarray
构造函数不再将 strides=()
解释为 strides=None
SeedSequence
不再与生成冲突
dtype=object
shape=0
到 numpy.rec
工厂函数已被废弃
np.complexfloating
标量的 round
操作
numpy.ndarray.tostring()
已被废弃,推荐使用 tobytes()
const
维度的更好支持
numpy.frompyfunc
现在接受一个 identity 参数
np.str_
标量现在支持缓冲区协议
numpy.copy
的 subok
选项
numpy.linalg.multi_dot
现在接受 out
参数
numpy.count_nonzero
的 keepdims
参数
numpy.array_equal
的 equal_nan
参数
np.float64
时,使用 AVX512 内部实现 np.exp
numpy.einsum
在子脚本列表中接受 NumPy int64
类型
np.logaddexp2.identity
更改为 -inf
__array__
的额外参数处理
numpy.random._bit_generator
移动到 numpy.random.bit_generator
pxd
文件提供对随机分布的 Cython 访问
numpy.random.multivariate_normal
中 eigh
和 cholesky
方法
MT19937.jumped
中跳转的实现
numpy.random
中添加多元超几何分布np.fromfile
和np.fromstring
将在错误数据上报错
ma.fill_value
中废弃非标量数组作为填充值
PyArray_As1D
,PyArray_As2D
np.alen
numpy.ma.mask_cols
和numpy.ma.mask_row
的axis
参数已废弃
numpy.lib.recfunctions.drop_fields
不再返回 None
numpy.argmin/argmax/min/max
在数组中存在,则返回NaT
np.can_cast(np.uint64, np.timedelta64, casting='safe')
为False
numpy.random.Generator.integers
中更改随机变量流
datetime64
和timedelta64
添加更多的 ufunc 循环
numpy.random
中的模块已移动
PyDataType_ISUNSIZED(descr)
对于结构化数据类型现在返回 False*.pxd
cython 导入文件
expand_dims
中
--f2cmap
选项
argwhere
在 0 维数组上现在产生一致的结果
random.permutation
和 random.shuffle
添加 axis
参数
method
关键字参数用于 np.random.multivariate_normal
numpy.fromstring
增加复数支持
axis
不为 None 时,numpy.unique
有一致的轴顺序
numpy.matmul
的布尔输出现在转换为布尔值
numpy.random.randint
在范围为 2**32
时产生不正确的值
numpy.fromfile
增加复数支持
gcc
命名的编译器现在添加 std=c99
参数](发布/1.18.0-说明.html#std-c99-added-if-compiler-is-named-gcc)
NaT
现在排序到数组的末尾
np.set_printoptions
中不正确的 threshold
会引发 TypeError
或 ValueError
numpy.distutils
在 LDFLAGS 和类似情况下的 append 行为发生更改
numpy.random.entropy
-Werror
构建
numpy.polynomial
函数在传递 float
而非 int
时会警告
numpy.distutils.exec_command
和 temp_file_name
numpy.nonzero
不应该再在 0d 数组上调用
numpy.broadcast_arrays
的结果会产生警告
float16
次正规化舍入
MaskedArray.mask
现在返回掩码的视图,而不是掩码本身
numpy.frombuffer
中查找 __buffer__
属性
out
在 take
, choose
, put
中用于内存重叠时被缓冲
i0
现在总是返回与输入相同形状的结果
can_cast
不再假设所有不安全的转换都是允许的
ndarray.flags.writeable
稍微更频繁地切换到 true
npy_intp const*
传递numpy.random
模块
ufunc.reduce
和相关函数现在接受一个 where
掩码
packbits
和 unpackbits
接受一个 order
关键字
unpackbits
现在接受一个 count
参数
linalg.svd
和 linalg.pinv
在 Hermitian 输入上可能更快
divmod
操作现在支持两个 timedelta64
操作数
fromfile
现在接受一个 offset
参数
pad
的新模式 “empty”
empty_like
和相关函数现在接受一个 shape
参数
as_integer_ratio
以匹配内置的 float
dtype
对象可以用多个字段名称进行索引
.npy
文件支持 Unicode 字段名称
fft
模块
numpy.ctypeslib
中对 ctypes
支持的进一步改进
numpy.errstate
现在也是一个函数装饰器
numpy.exp
和 numpy.log
在 float32 实现上加速
numpy.pad
的性能
numpy.interp
更稳健地处理无穷大
Pathlib
支持fromfile
, tofile
和ndarray.dump
isnan
, isinf
和isfinite
ufuncs
isfinite
支持datetime64
和timedelta64
类型
nan_to_num
中添加了新的关键字
floor
, ceil
和trunc
现在尊重内置魔术方法
quantile
现在可以在Fraction和decimal.Decimal
对象上使用
matmul
中支持对象数组
median
和percentile
函数族不再对nan
发出警告
timedelta64 % 0
行为调整为返回NaT
__array_function__
进行重写
lib.recfunctions.structured_to_unstructured
不会压缩单个字段视图
clip
现在在底层使用 ufunc
__array_interface__
偏移现在按照文档正常工作
savez
函数中将 pickle 协议设置为 3 以强制使用 zip64 标志
KeyError
而不是ValueError
matmul (*@* operator)
与对象数组一起使用。numpy.lib.recfunctions.structured_to_unstructured
不会压缩单字段视图__array_interface__
偏移现在按照文档工作timedelta64
操作数现在支持 divmod 操作np.ctypeslib
中ctypes
支持的进一步改进
timedelta64 % 0
的行为以返回NaT
(timedelta64 % 0 behavior adjusted to return NaT)complex64/128
的对齐方式已更改(complex64/128 alignment has changed)
nd_grid __len__
已移除(nd_grid len removal)
np.unravel_index
现在接受shape
关键字参数
histogram
中添加了综合平方误差(ISE)估计器(integrated squared error (ISE) estimator added to histogram)
np.loadtxt
添加了max_rows
关键字(max_rows keyword added for np.loadtxt)
np.timedelta64
操作数现在有模运算支持(modulus operator support added for np.timedelta64 operands)
np.polynomial.Polynomial
*类会在 Jupyter 笔记本中以 LaTeX 渲染(np.polynomial.Polynomial classes render in LaTeX in Jupyter notebooks)
randint
和choice
现在适用于空分布(randint and choice now work on empty distributions)
linalg.lstsq
, linalg.qr
, 和 linalg.svd
现在适用于空数组(linalg.lstsq, linalg.qr, and linalg.svd now work with empty arrays)
PEP3118
格式字符串会抛出更好的错误消息以链式异常处理(Chain exceptions to give better error messages for invalid PEP3118 format strings)
numpy.angle
和numpy.expand_dims
现在适用于ndarray
子类
NPY_NO_DEPRECATED_API
编译器警告抑制
np.diff
添加了 kwargs prepend 和 append
np.clip
和clip
方法检查内存重叠
np.polyfit
中cov
选项的新值unscaled
__module__
属性现在指向公共模块
np.block
大型数组的速度
np.take
ndpointer.contents
成员
matmul
现在是一个ufunc
linspace
,logspace
和geomspace
的起始和停止数组
positive
现在会对非数值数组发出弃用警告
NDArrayOperatorsMixin
现在实现矩阵乘法
np.polyfit
中协方差矩阵的缩放方式不同
maximum
和 minimum
不再发出警告
getfield
的有效性检查已扩展
__array_function__
进行覆盖
writeable
np.savez
返回的 NpzFile
现在是 collections.abc.Mapping
nditer
__array_interface__
向 ctypes
施加修改
np.ma.notmasked_contiguous
和 np.ma.flatnotmasked_contiguous
现在总是返回列表
np.squeeze
恢复了无法处理 axis
参数的对象的旧行为
.item
方法现在返回一个字节对象
copy.copy
和 copy.deepcopy
不再将 masked
转换为数组
npy_get_floatstatus_barrier
和 npy_clear_floatstatus_barrier
PyArray_GetDTypeTransferFunction
更改
np.gcd
和 np.lcm
函数现针对整数和对象类型
np.intersect1d
添加了 return_indices
关键字
np.quantile
和 np.nanquantile
np.einsum
更新
np.ufunc.reduce
和相关函数现在接受初始值
np.flip
可以在多个轴上操作
histogram
和 histogramdd
函数已移至 np.lib.histograms
histogram
将接受 NaN 值
histogram
可以处理日期时间类型 (release/1.15.0-notes.html#histogram-works-on-datetime-types-when-explicit-bin-edges-are-given)
histogram
的“auto”估计器更好地处理有限方差 (release/1.15.0-notes.html#histogram-auto-estimator-handles-limited-variance-better)
histogram
和 histogramdd
返回的边界现在与数据的浮点类型匹配 (release/1.15.0-notes.html#the-edges-returned-by-histogram-and-histogramdd-now-match-the-data-float-type)
histogramdd
允许在一部分轴上给定显式范围 (release/1.15.0-notes.html#histogramdd-allows-explicit-ranges-to-be-given-in-a-subset-of-axes)
histogramdd
和 histogram2d
的 normed 参数已重命名 (release/1.15.0-notes.html#the-normed-arguments-of-histogramdd-and-histogram2d-have-been-renamed)
np.r_
与 0d 数组一起使用,np.ma.mr_
与 np.ma.masked
一起使用 (release/1.15.0-notes.html#np-r-works-with-0d-arrays-and-np-ma-mr-works-with-np-ma-masked)
np.ptp
接受keepdims
参数和扩展的轴元组 (release/1.15.0-notes.html#np-ptp-accepts-a-keepdims-argument-and-extended-axis-tuples)
MaskedArray.astype
现在与 ndarray.astype
相同
nan_to_num
总是返回标量 (release/1.15.0-notes.html#nan-to-num-always-returns-scalars-when-receiving-scalar-or-0d-inputs)
np.flatnonzero
在 numpy 可转换类型上工作 (release/1.15.0-notes.html#np-flatnonzero-works-on-numpy-convertible-types)
np.interp
返回 numpy 标量,而不是内建标量
dtype=object
,覆盖默认的bool
(release/1.15.0-notes.html#comparison-ufuncs-accept-dtype-object-overriding-the-default-bool)
sort
函数接受kind='stable'
(release/1.15.0-notes.html#sort-functions-accept-kind-stable)
linalg.matrix_power
现在可以处理矩阵堆栈
random.permutation
性能提高了 (release/1.15.0-notes.html#increased-performance-in-random-permutation-for-multidimensional-arrays)
axes
、axis
和keepdims
参数 (release/1.15.0-notes.html#generalized-ufuncs-now-accept-axes-axis-and-keepdims-arguments)
np.take_along_axis
和np.put_along_axis
函数
np.ma.masked
不再可写
np.ma
函数生成的fill_value
已更改
a.flat.__array__()
在a
不连续时返回不可写的数组
np.tensordot
现在在收缩为 0 长度的维度时返回零数组
numpy.testing
重新组织
np.asfarray
不再接受非数据类型的dtype
参数
np.linalg.norm
保留浮点输入类型,即使对于任意阶数
count_nonzero(arr, axis=())
现在计数不包括任何轴,而不是所有轴
__init__.py
文件已添加到测试目录
void
数组,现在调用.astype(bool)
将在每个元素上调用bool
。
MaskedArray.squeeze
永远不会返回np.ma.masked
。
can_cast
的第一个参数从from
重命名为from_
。
isnat
会引发TypeError
。
dtype.__getitem__
会引发TypeError
。
__str__
和__repr__
。
UPDATEIFCOPY
数组的 PyPy 兼容替代方法。nose
插件可被numpy.testing.Tester
使用。
numpy.testing
中新增了parametrize
装饰器。
numpy.polynomial.chebyshev
中新增了chebinterpolate
函数。
lzma
压缩文本文件。
np.setprintoptions
和np.array2string
中新增了sign
选项。
np.linalg.matrix_rank
中新增了hermitian
选项。
np.array2string
中新增了threshold
和edgeitems
选项。
concatenate
和stack
新增了out
参数。
random.noncentral_f
中,分子自由度只需为正数。
np.einsum
变体都释放了 GIL](release/1.14.0-notes.html#the-gil-is-released-for-all-np-einsum-variations)
f2py
现在处理 0 维数组](release/1.14.0-notes.html#f2py-now-handles-arrays-of-dimension-0)
numpy.distutils
支持同时使用 MSVC 和 mingw64-gfortran](release/1.14.0-notes.html#numpy-distutils-supports-using-msvc-and-mingw64-gfortran-together)
np.linalg.pinv
现在可以作用于堆叠矩阵](release/1.14.0-notes.html#np-linalg-pinv-now-works-on-stacked-matrices)
numpy.save
将数据对齐到 64 字节而不是 16
np.lib.financial
中支持decimal.Decimal
](release/1.14.0-notes.html#support-for-decimal-decimal-in-np-lib-financial)
void
数据类型元素现在以十六进制表示打印](release/1.14.0-notes.html#void-datatype-elements-are-now-printed-in-hex-notation)
void
数据类型的打印风格现在可以单独定制](release/1.14.0-notes.html#printing-style-for-void-datatypes-is-now-independently-customizable)
np.loadtxt
的内存使用量减少](release/1.14.0-notes.html#reduced-memory-usage-of-np-loadtxt)
np.set_string_function
影响](release/1.14.0-notes.html#integer-and-void-scalars-are-now-unaffected-by-np-set-string-function)
style
参数](release/1.14.0-notes.html#d-array-printing-changed-style-arg-of-array2string-deprecated)
RandomState
需要一个 1-d 数组](release/1.14.0-notes.html#seeding-randomstate-using-an-array-requires-a-1-d-array)
MaskedArray
对象显示更有用的 repr
](release/1.14.0-notes.html#maskedarray-objects-show-a-more-useful-repr)
np.polynomial
类的repr
更为明确
__getslice__
和__setslice__
在ndarray
子类中不再需要
...
(省略号)索引 MaskedArrays/Constants 现在返回 MaskedArray
PyArray_MapIterArrayCopyIfOverlap
到 NumPy C-API
__array_ufunc__
positive
ufunc
divmod
ufunc
np.isnat
ufunc 用于测试 NaT 特殊日期和时间差值的值
np.heaviside
ufunc 计算 Heaviside 函数
np.block
函数
isin
函数,改进in1d
unique
的axes
参数
np.gradient
现在支持不均匀间隔的数据
apply_along_axis
中返回任意维度的数组
dtype
添加了 .ndim
属性来补充 .shape
(查看详情)
packbits
和 unpackbits
的性能改进(查看详情)
ndarray
子类的更好的默认 repr(查看详情)
np.matrix
中的布尔元素现在可以使用字符串语法创建(查看详情)
linalg
操作现在接受空向量和矩阵(查看详情)
np.hypot.reduce
和 np.logical_xor
的reduce
在更多情况下被允许(查看详情)
repr
(查看详情)
argsort
现在具有与 sort
相同的默认参数(查看详情)
average
现在保留子类(查看详情)
array == None
和 array != None
现在进行按元素比较(查看详情)
np.equal, np.not_equal
忽略对象身份(查看详情)
np.random.multivariate_normal
在坏协方差矩阵下的行为(查看详情)
assert_array_less
现在对比 np.inf
和 -np.inf
(查看详情)
assert_array_
和屏蔽数组assert_equal
隐藏了较少的警告
memmap
对象中的offset
属性值
np.real
和np.imag
为标量输入返回标量
data
属性分配
linspace
中 num 属性的不安全的整型转换
binary_repr
的位宽参数不足
power
和**
会报错
np.percentile
的“midpoint”插值方法修复确切指数
keepdims
参数传递给用户类方法
bitwise_and
的身份变化
assert_almost_equal
更加一致
NoseTester
在测试期间的警告行为
assert_warns
和deprecated
装饰器更具体
as_strided
的writeable
关键字参数
rot90
的axes
关键字参数
flip
numpy.distutils
中的 BLIS 支持
numpy/__init__.py
中加入运行分发特定检查的钩子
nancumsum
和nancumprod
函数
np.interp
现在可以插值复数值
polyvalfromroots
geomspace
ma.convolve
和ma.correlate
float_power
通用函数
np.loadtxt
支持单个整数作为usecol
参数
histogram
的改进的自动化箱估计器
np.roll
现在可以同时滚动多个轴
__complex__
方法
pathlib.Path
对象
np.finfo
的新bits
属性
np.vectorize
的新signature
参数
numpy.sctypes
现在在 Python3 中也包括bytes
bitwise_and
的特性变化
np.einsum
中的操作次序优化
ediff1d
提高了性能和 subclass 处理
ndarray.mean
精度
linalg.norm
返回类型更改
TypeError
而不是ValueError
%
和 //
运算符
np.gradient
现在支持 axis
参数](release/1.11.0-notes.html#np-gradient-now-supports-an-axis-argument)
np.lexsort
现在支持具有对象数据类型的数组](release/1.11.0-notes.html#np-lexsort-now-supports-arrays-with-object-data-type)
np.ma.core.MaskedArray
现在支持 order
参数](release/1.11.0-notes.html#np-ma-core-maskedarray-now-supports-an-order-argument)
ndarray.tofile
现在在 linux 上使用 fallocate](release/1.11.0-notes.html#ndarray-tofile-now-uses-fallocate-on-linux)
A.T @ A
和 A @ A.T
形式操作的优化](release/1.11.0-notes.html#optimizations-for-operations-of-the-form-a-t-a-and-a-a-t)
np.testing.assert_warns
现在可以作为上下文管理器使用](release/1.11.0-notes.html#np-testing-assert-warns-can-now-be-used-as-a-context-manager)
numpy.distutils
中删除了 Pyrex 支持](release/1.11.0-notes.html#pyrex-support-was-removed-from-numpy-distutils)
np.broadcast
现在可以用单个参数调用](release/1.11.0-notes.html#np-broadcast-can-now-be-called-with-a-single-argument)
np.trace
现在尊重数组子类](release/1.11.0-notes.html#np-trace-now-respects-array-subclasses)
np.dot
现在引发 TypeError
而不是 ValueError
](release/1.11.0-notes.html#id1)
linalg.norm
返回类型发生变化](release/1.11.0-notes.html#id2)
testing
命名空间中的随机数生成器
MaskedArray
的切片/视图赋值numpy.i
中的 swig bug
axis=0
之外的任何轴对 1d 数组进行连接都会引发IndexError
max_rows
参数
fweights
和 aweights
参数
norm
pad_width
和 constant_values
out
参数
float.hex
方法生成的字符串
promote_types
and string dtype
can_cast
and string dtype
doc/swig
directory moved
npy_3kcompat.h
header changed
sq_item
and sq_ass_item
sequence methods
zeros_like
for string dtypes now returns empty strings
Dtype
参数。
np.triu
和 np.tril
的更一般的广播支持。
tostring
方法的 tobytes
别名。
numbers
模块的兼容性。
np.vander
添加了 increasing
参数。
np.unique
添加了 unique_counts
参数。
nanfunctions
中对中位数和百分位数的支持。
np.cross
的全广播支持。
np.partition
实现的百分位数。
np.array
的性能改进。
np.searchsorted
的性能改进。
np.random.multivariate_normal
中的协方差检查。
select
输入的弃用。
rank
函数。
numpy.core
numpy.lib
numpy.distutils
numpy.random
numpy.f2py
numpy.poly
numpy.polynomial
中的 Legendre、Laguerre、Hermite、HermiteE 多项式
numpy.f2py
中支持 Fortran 隐式形状数组和大小函数
默认错误处理
numpy.distutils
numpy.testing
C API
numpy.fft
numpy.memmap
numpy.lib
numpy.ma
numpy.distutils