Array manipulation routines

Changing array shape

reshape(a, newshape[, order, out])

Gives a new shape to an array without changing its data.

ravel(x)

Return a contiguous flattened array.

ndarray.flatten([order])

Return a copy of the array collapsed into one dimension.

Transpose-like operations

swapaxes(a, axis1, axis2)

Interchange two axes of an array.

ndarray.T

Same as self.transpose().

transpose(a[, axes])

Permute the dimensions of an array.

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.

Changing number of dimensions

expand_dims(a, axis)

Expand the shape of an array.

squeeze(a[, axis, out])

Remove single-dimensional entries from the shape of an array.

broadcast_to(array, shape)

Broadcast an array to a new shape.

broadcast_arrays(*args)

Broadcast any number of arrays against each other.

atleast_1d(*arys)

Convert inputs to arrays with at least one dimension.

atleast_2d(*arys)

Convert inputs to arrays with at least two dimensions.

atleast_3d(*arys)

Convert inputs to arrays with at least three dimension.

Joining arrays

concatenate(seq[, axis, out])

Join a sequence of arrays along an existing axis.

stack(arrays[, axis, out])

Join a sequence of arrays along a new axis.

dstack(arrays)

Stack arrays in sequence depth wise (along third axis).

vstack(arrays[, out])

Stack arrays in sequence vertically (row wise).

column_stack(tup)

Stack 1-D arrays as columns into a 2-D array.

hstack(arrays)

Stack arrays in sequence horizontally (column wise).

Splitting arrays

split(ary, indices_or_sections[, axis])

Split an array into multiple sub-arrays.

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

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

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.

Adding and removing elements

unique(ar[, return_index, return_inverse, …])

Find the unique elements of an array.

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.

Rearranging elements

reshape(a, newshape[, order, out])

Gives a new shape to an array without changing its data.

flip(m[, axis, out])

Reverse the order of elements in an array along the given axis.

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.

fliplr(*args, **kwargs)

Flip array in the left/right direction.

flipud(*args, **kwargs)

Flip array in the up/down direction.