Array manipulation routines#

Basic operations#

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

Copies values from one array to another with broadcasting.

shape(a)

Returns the shape of an array

Changing array shape#

reshape(a, newshape[, order])

Returns an array with new shape and same elements.

ravel(a[, order])

Returns a flattened array.

Transpose-like operations#

moveaxis(a, source, destination)

Moves axes of an array to new positions.

rollaxis(a, axis[, start])

Moves the specified axis backwards to the given place.

swapaxes(a, axis1, axis2)

Swaps the two axes.

transpose(a[, axes])

Permutes the dimensions of an array.

See also

cupy.ndarray.T

Changing number of dimensions#

atleast_1d(*arys)

Converts arrays to arrays with dimensions >= 1.

atleast_2d(*arys)

Converts arrays to arrays with dimensions >= 2.

atleast_3d(*arys)

Converts arrays to arrays with dimensions >= 3.

broadcast(*arrays)

Object that performs broadcasting.

broadcast_to(array, shape)

Broadcast an array to a given shape.

broadcast_arrays(*args)

Broadcasts given arrays.

expand_dims(a, axis)

Expands given arrays.

squeeze(a[, axis])

Removes size-one axes from the shape of an array.

Changing kind of array#

asarray(a[, dtype, order, copy, blocking])

Converts an object to array.

asanyarray(a[, dtype, order, copy, blocking])

Converts an object to array.

asfarray(a[, dtype])

Converts array elements to float type.

asfortranarray(a[, dtype])

Return an array laid out in Fortran order in memory.

ascontiguousarray(a[, dtype])

Returns a C-contiguous array.

asarray_chkfinite(a[, dtype, order])

Converts the given input to an array, and raises an error if the input contains NaNs or Infs.

require(a[, dtype, requirements])

Return an array which satisfies the requirements.

Joining arrays#

concatenate(tup[, axis, out, dtype, casting])

Joins arrays along an axis.

stack(tup[, axis, out, dtype, casting])

Stacks arrays along a new axis.

vstack(tup, *[, dtype, casting])

Stacks arrays vertically.

hstack(tup, *[, dtype, casting])

Stacks arrays horizontally.

dstack(tup)

Stacks arrays along the third axis.

column_stack(tup)

Stacks 1-D and 2-D arrays as columns into a 2-D array.

row_stack(tup, *[, dtype, casting])

Stacks arrays vertically.

Splitting arrays#

split(ary, indices_or_sections[, axis])

Splits an array into multiple sub arrays along a given axis.

array_split(ary, indices_or_sections[, axis])

Splits an array into multiple sub arrays along a given axis.

dsplit(ary, indices_or_sections)

Splits an array into multiple sub arrays along the third axis.

hsplit(ary, indices_or_sections)

Splits an array into multiple sub arrays horizontally.

vsplit(ary, indices_or_sections)

Splits an array into multiple sub arrays along the first axis.

Tiling arrays#

tile(A, reps)

Construct an array by repeating A the number of times given by reps.

repeat(a, repeats[, axis])

Repeat arrays along an axis.

Adding and removing elements#

delete(arr, indices[, axis])

Delete values from an array along the specified axis.

append(arr, values[, axis])

Append values to the end of an array.

resize(a, new_shape)

Return a new array with the specified shape.

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

Find the unique elements of an array.

trim_zeros(filt[, trim])

Trim the leading and/or trailing zeros from a 1-D array or sequence.

Rearranging elements#

flip(a[, axis])

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

fliplr(a)

Flip array in the left/right direction.

flipud(a)

Flip array in the up/down direction.

reshape(a, newshape[, order])

Returns an array with new shape and same elements.

roll(a, shift[, axis])

Roll array elements along a given axis.

rot90(a[, k, axes])

Rotate an array by 90 degrees in the plane specified by axes.