ndarray的数据常规操作

复制

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

累积和


np.cumsum():返回累积和

改变数组形状


  • np.shape(a,newshape[,order]):gives a new shape to an array changing its data.
  • np.ravel(a,order):Return a contiguous flattened array.
  • np.flat():A 1-D iterator over the array
  • ndarray.flatten(order=’C’)
    Return a copy of the array collapsed into one dimension.
    Parameters order [{‘C’, ‘F’, ‘A’, ‘K’}, optional]
    ‘C’ means to flatten in row-major (C-style) order.
    ‘F’ means to flatten in column-major (Fortran- style) order.
    ‘A’ means to flatten in columnmajor order if a is Fortran contiguous in memory, row-major order otherwise.
    ‘K’ means to flatten a in the order the elements occur in memory.
    The default is ‘C’.
    Returns :y [ndarray] A copy of the input array, flattened to one dimension.

hsplit()


Split an array into multiple sub-arrays horizontally (column-wise)

x =array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[ 12., 13., 14., 15.]])

np.hsplit(x, np.array([3, 6]))

[array([[ 0., 1., 2.],
[ 4., 5., 6.],
[ 8., 9., 10.],
[ 12., 13., 14.]]),
array([[ 3.],
[ 7.],
[ 11.],
[ 15.]]),
array([], dtype=float64)]

转置操作(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 Same as self.transpose(), except that self is returned if
    self.ndim < 2.
  • transpose(a[, axes]) Permute the dimensions of an array

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.

猜你喜欢

转载自blog.csdn.net/qq_28485501/article/details/85243213
今日推荐