Array manipulation routines

Basic operations

methoddescription
copytoopen in new window(dst, src[, casting, where])Copies values from one array to another, broadcasting as necessary.

Changing array shape

methoddescription
reshapeopen in new window(a, newshape[, order])Gives a new shape to an array without changing its data.
ravelopen in new window(a[, order])Return a contiguous flattened array.
ndarray.flatopen in new windowA 1-D iterator over the array.
ndarray.flattenopen in new window([order])Return a copy of the array collapsed into one dimension.

Transpose-like operations

methoddescription
moveaxisopen in new window(a, source, destination)Move axes of an array to new positions.
rollaxisopen in new window(a, axis[, start])Roll the specified axis backwards, until it lies in a given position.
swapaxesopen in new window(a, axis1, axis2)Interchange two axes of an array.
ndarray.Topen in new windowThe transposeopen in new windowd array.
transpose(a[, axes])Permute the dimensions of an array.

Changing number of dimensions

methoddescription
atleast_1dopen in new window(*arys)Convert inputs to arrays with at least one dimension.
atleast_2dopen in new window(*arys)View inputs as arrays with at least two dimensions.
atleast_3dopen in new window(*arys)View inputs as arrays with at least three dimensions.
broadcastopen in new windowProduce an object that mimics broadcasting.
broadcast_toopen in new window(array, shape[, subok])Broadcast an array to a new shape.
broadcast_arraysopen in new window(*args, **kwargs)Broadcast any number of arrays against each other.
expand_dimsopen in new window(a, axis)Expand the shape of an array.
squeezeopen in new window(a[, axis])Remove single-dimensional entries from the shape of an array.

Changing kind of array

methoddescription
asarrayopen in new window(a[, dtype, order])Convert the input to an array.
asanyarrayopen in new window(a[, dtype, order])Convert the input to an ndarray, but pass ndarray subclasses through.
asmatrixopen in new window(data[, dtype])Interpret the input as a matrix.
asfarrayopen in new window(a[, dtype])Return an array converted to a float type.
asfortranarrayopen in new window(a[, dtype])Return an array (ndim >= 1) laid out in Fortran order in memory.
ascontiguousarrayopen in new window(a[, dtype])Return a contiguous array (ndim >= 1) in memory (C order).
asarray_chkfiniteopen in new window(a[, dtype, order])Convert the input to an array, checking for NaNs or Infs.
asscalaropen in new window(a)Convert an array of size 1 to its scalar equivalent.
requireopen in new window(a[, dtype, requirements])Return an ndarray of the provided type that satisfies requirements.

Joining arrays

methoddescription
concatenateopen in new window((a1, a2, …)[, axis, out])Join a sequence of arrays along an existing axis.
stackopen in new window(arrays[, axis, out])Join a sequence of arrays along a new axis.
column_stackopen in new window(tup)Stack 1-D arrays as columns into a 2-D array.
dstackopen in new window(tup)Stack arrays in sequence depth wise (along third axis).
hstackopen in new window(tup)Stack arrays in sequence horizontally (column wise).
vstackopen in new window(tup)Stack arrays in sequence vertically (row wise).
blockopen in new window(arrays)Assemble an nd-array from nested lists of blocks.

Splitting arrays

methoddescription
splitopen in new window(ary, indices_or_sections[, axis])Split an array into multiple sub-arrays.
array_splitopen in new window(ary, indices_or_sections[, axis])Split an array into multiple sub-arrays.
dsplitopen in new window(ary, indices_or_sections)Split array into multiple sub-arrays along the 3rd axis (depth).
hsplitopen in new window(ary, indices_or_sections)Split an array into multiple sub-arrays horizontally (column-wise).
vsplitopen in new window(ary, indices_or_sections)Split an array into multiple sub-arrays vertically (row-wise).

Tiling arrays

methoddescription
tileopen in new window(A, reps)Construct an array by repeatopen in new windowing A the number of times given by reps.
repeat(a, repeats[, axis])Repeat elements of an array.

Adding and removing elements

methoddescription
deleteopen in new window(arr, obj[, axis])Return a new array with sub-arrays along an axis deleted.
insertopen in new window(arr, obj, values[, axis])Insert values along the given axis before the given indices.
appendopen in new window(arr, values[, axis])Append values to the end of an array.
resizeopen in new window(a, new_shape)Return a new array with the specified shape.
trim_zerosopen in new window(filt[, trim])Trim the leading and/or trailing zeros from a 1-D array or sequence.
uniqueopen in new window(ar[, return_index, return_inverse, …])Find the unique elements of an array.

Rearranging elements

methoddescription
flipopen in new window(m[, axis])Reverse the order of elements in an array along the given axis.
fliplropen in new window(m)Flip array in the left/right direction.
flipudopen in new window(m)Flip array in the up/down direction.
reshapeopen in new window(a, newshape[, order])Gives a new shape to an array without changing its data.
rollopen in new window(a, shift[, axis])Roll array elements along a given axis.
rot90open in new window(m[, k, axes])Rotate an array by 90 degrees in the plane specified by axes.