numpy官方文档整理—数组操作例程(Array manipulation routines)

24 篇文章 5 订阅


对应的官方链接 https://docs.scipy.org/doc/numpy/reference/routines.array-manipulation.html#basic-operations

1. Basic operations 基本操作

copyto(dst, src[, casting, where]) Copies values from one array to another, broadcasting as necessary.

2. Changing array shape 改变数组形状

reshape(a, newshape[, order]) Gives a new shape to an array without changing its data.
ravel(a[, order]) Return a contiguous flattened array.
ndarray.flat A 1-D iterator over the array.
ndarray.flatten([order]) Return a copy of the array collapsed into one dimension.

3. Transpose-like operations 转置类操作

moveaxis(a, source, destination) Move axes of an array to new positions.
rollaxis(a, axis[, start]) Roll the specified axis backwards, until it lies in a given position.
swapaxes(a, axis1, axis2) Interchange two axes of an array.
ndarray.T The transposed array.
transpose(a[, axes]) Permute the dimensions of an array.

4. Changing number of dimensions 改变维数

atleast_1d(*arys) Convert inputs to arrays with at least one dimension.
atleast_2d(*arys) View inputs as arrays with at least two dimensions.
atleast_3d(*arys) View inputs as arrays with at least three dimensions.
broadcast Produce an object that mimics broadcasting.
broadcast_to(array, shape[, subok]) Broadcast an array to a new shape.
broadcast_arrays(*args, **kwargs) Broadcast any number of arrays against each other.
expand_dims(a, axis) Expand the shape of an array.
squeeze(a[, axis]) Remove single-dimensional entries from the shape of an array.

5. Changing kind of array 改变矩阵的类型

asarray(a[, dtype, order]) Convert the input to an array.
asanyarray(a[, dtype, order]) Convert the input to an ndarray, but pass ndarray subclasses through.
asmatrix(data[, dtype]) Interpret the input as a matrix.
asfarray(a[, dtype]) Return an array converted to a float type.
asfortranarray(a[, dtype]) Return an array (ndim >= 1) laid out in Fortran order in memory.
ascontiguousarray(a[, dtype]) Return a contiguous array (ndim >= 1) in memory (C order).
asarray_chkfinite(a[, dtype, order]) Convert the input to an array, checking for NaNs or Infs.
asscalar(a) Convert an array of size 1 to its scalar equivalent.
require(a[, dtype, requirements]) Return an ndarray of the provided type that satisfies requirements.

6. Joining arrays 矩阵合并

操作英文说明中文说明通俗说明
concatenate((a1, a2, …)[, axis, out])Join a sequence of arrays along an existing axis.沿着现有的轴加入一系列数组。
stack(arrays[, axis, out])Join a sequence of arrays along a new axis.
column_stack(tup)Stack 1-D arrays as columns into a 2-D array.
dstack(tup)Stack arrays in sequence depth wise (along third axis).
hstack(tup)Stack arrays in sequence horizontally (column wise).水平(按列)顺序堆叠数组。在左边或者右边添加矩阵
vstack(tup)Stack arrays in sequence vertically (row wise).垂直(按行)顺序堆叠数组。在上边或者下边添加矩阵
block(arrays)Assemble an nd-array from nested lists of blocks.

7. Splitting arrays 矩阵分割

split(ary, indices_or_sections[, axis]) Split an array into multiple sub-arrays.
array_split(ary, indices_or_sections[, axis]) Split an array into multiple sub-arrays.
dsplit(ary, indices_or_sections) Split array into multiple sub-arrays along the 3rd axis (depth).
hsplit(ary, indices_or_sections) Split an array into multiple sub-arrays horizontally (column-wise).
vsplit(ary, indices_or_sections) Split an array into multiple sub-arrays vertically (row-wise).

8. Tiling arrays 矩阵拓展(重复性地)

tile(A, reps) Construct an array by repeating A the number of times given by reps.
repeat(a, repeats[, axis]) Repeat elements of an array.

9. Adding and removing elements 增删元素

delete(arr, obj[, axis]) Return a new array with sub-arrays along an axis deleted.
insert(arr, obj, values[, axis]) Insert values along the given axis before the given indices.
append(arr, values[, axis]) Append values to the end of an array.
resize(a, new_shape) Return a new array with the specified shape.
trim_zeros(filt[, trim]) Trim the leading and/or trailing zeros from a 1-D array or sequence.
unique(ar[, return_index, return_inverse, …]) Find the unique elements of an array.

10. Rearranging elements 对元素进行重新排列

flip(m[, axis]) Reverse the order of elements in an array along the given axis.
fliplr(m) Flip array in the left/right direction.
flipud(m) Flip array in the up/down direction.
reshape(a, newshape[, order]) Gives a new shape to an array without changing its data.
roll(a, shift[, axis]) Roll array elements along a given axis.
rot90(m[, k, axes]) Rotate an array by 90 degrees in the plane specified by axes.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千行百行

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值