numpy-docs/reference/routines.array-manipulation.rst

View Log Diff to SVN Discussion Source
  • Review status: Needs review
  • OK to apply

Array manipulation routines

Changing array shape

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

Transpose-like operations

rollaxis Roll the specified axis backwards, until it lies in a given position.
swapaxes Interchange two axes of an array.
ndarray.T Same as self.transpose() except self is returned for self.ndim < 2.
transpose Permute the dimensions of an array.

Changing number of dimensions

atleast_1d Convert inputs to arrays with at least one dimension.
atleast_2d View inputs as arrays with at least two dimensions.
atleast_3d View inputs as arrays with at least three dimensions.
broadcast Produce an object that mimics broadcasting.
broadcast_arrays Broadcast any number of arrays against each other.
expand_dims Expand the shape of an array.
squeeze Remove single-dimensional entries from the shape of an array.

Changing kind of array

asarray Convert the input to an array.
asanyarray Convert the input to a ndarray, but pass ndarray subclasses through.
asmatrix Interpret the input as a matrix.
asfarray Return an array converted to a float type.
asfortranarray Return an array laid out in Fortran order in memory.
asscalar Convert an array of size 1 to its scalar equivalent.
require Return an ndarray of the provided type that satisfies requirements.

Joining arrays

column_stack Stack 1-D arrays as columns into a 2-D array.
concatenate Join a sequence of arrays together.
dstack Stack arrays in sequence depth wise (along third axis).
hstack Stack arrays in sequence horizontally (column wise).
vstack Stack arrays in sequence vertically (row wise).

Splitting arrays

array_split Split an array into multiple sub-arrays of equal or near-equal size.
dsplit Split array into multiple sub-arrays along the 3rd axis (depth).
hsplit Split an array into multiple sub-arrays horizontally (column-wise).
split Split an array into multiple sub-arrays of equal size.
vsplit Split an array into multiple sub-arrays vertically (row-wise).

Tiling arrays

tile Construct an array by repeating A the number of times given by reps.
repeat Repeat elements of an array.

Adding and removing elements

delete Return a new array with sub-arrays along an axis deleted.
insert Insert values along the given axis before the given indices.
append Append values to the end of an array.
resize Return a new array with the specified shape.
trim_zeros Trim the leading and/or trailing zeros from a 1-D array or sequence.
unique Return the sorted, unique elements of an array or sequence.

Rearranging elements

fliplr Flip array in the left/right direction.
flipud Flip array in the up/down direction.
reshape Gives a new shape to an array without changing its data.
roll Roll array elements along a given axis.
rot90 Rotate an array by 90 degrees in the counter-clockwise direction.