数组操作例程#

基本操作#

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])

置换数组的维度。

另请参阅

cupy.ndarray.T

改变维度数量#

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])

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

改变数组类型#

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])

将给定输入转换为数组,如果输入包含 NaNs 或 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)

将一维和二维数组作为列堆叠成一个二维数组。

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 指定次数来构造一个数组。

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 度。