数组操作例程#

基本操作#

copyto(dst, src[, casting, where])

通过广播从一个数组复制值到另一个数组。

shape(a)

返回数组的形状

改变数组形状#

reshape(a, newshape[, order])

返回一个具有新形状和相同元素的数组。

ravel(a[, order])

返回一个扁平化的数组。

类似转置的操作#

moveaxis(a, source, destination)

将数组的轴移动到新位置。

rollaxis(a, axis[, start])

将指定的轴向后移动到给定的位置。

swapaxes(a, axis1, axis2)

交换两个轴。

transpose(a[, axes])

置换数组的维度。

更改维度数量#

atleast_1d(*arys)

将数组转换为维度 >= 1 的数组。

atleast_2d(*arys)

将数组转换为维度 >= 2 的数组。

atleast_3d(*arys)

将数组转换为维度 >= 3 的数组。

broadcast(*arrays)

执行广播的对象。

broadcast_to(array, shape)

将数组广播到给定的形状。

broadcast_arrays(*args)

广播给定的数组。

expand_dims(a, axis)

扩展给定的数组。

squeeze(a[, axis])

从数组的形状中移除大小为一的轴。

更改数组类型#

asarray(a[, dtype, order, blocking])

将对象转换为数组。

asanyarray(a[, dtype, order, blocking])

将对象转换为数组。

asfarray(a[, dtype])

将数组元素转换为浮点类型。

asfortranarray(a[, dtype])

返回一个在内存中按Fortran顺序排列的数组。

ascontiguousarray(a[, dtype])

返回一个C连续的数组。

asarray_chkfinite(a[, dtype, order])

将给定的输入转换为数组,如果输入包含NaN或Infs则引发错误。

require(a[, dtype, requirements])

返回一个满足要求的数组。

连接数组#

concatenate(tup[, axis, out, dtype, casting])

沿轴连接数组。

stack(tup[, axis, out, dtype, casting])

沿新轴堆叠数组。

vstack(tup, *[, dtype, casting])

垂直堆叠数组。

hstack(tup, *[, dtype, casting])

水平堆叠数组。

dstack(tup)

沿第三个轴堆叠数组。

column_stack(tup)

将 1-D 和 2-D 数组作为列堆叠成一个 2-D 数组。

row_stack(tup, *[, dtype, casting])

垂直堆叠数组。

分割数组#

split(ary, indices_or_sections[, axis])

沿给定轴将数组拆分为多个子数组。

array_split(ary, indices_or_sections[, axis])

沿给定轴将数组拆分为多个子数组。

dsplit(ary, indices_or_sections)

沿第三个轴将数组分割成多个子数组。

hsplit(ary, indices_or_sections)

将一个数组水平分割成多个子数组。

vsplit(ary, indices_or_sections)

将一个数组沿第一个轴分割成多个子数组。

平铺数组#

tile(A, reps)

通过重复 A 的次数来构造一个数组,次数由 reps 给出。

repeat(a, repeats[, axis])

沿轴重复数组。

添加和删除元素#

delete(arr, indices[, axis])

沿指定轴从数组中删除值。

append(arr, values[, axis])

将值追加到数组的末尾。

resize(a, new_shape)

返回一个具有指定形状的新数组。

unique(ar[, return_index, return_inverse, ...])

查找数组中的唯一元素。

trim_zeros(filt[, trim])

从一个一维数组或序列中去除前导和/或尾随的零。

重新排列元素#

flip(a[, axis])

沿给定轴反转数组中元素的顺序。

fliplr(a)

在左/右方向翻转数组。

flipud(a)

在上下方向翻转数组。

reshape(a, newshape[, order])

返回一个具有新形状和相同元素的数组。

roll(a, shift[, axis])

沿给定轴滚动数组元素。

rot90(a[, k, axes])

在由轴指定的平面内将数组旋转90度。