Share @ LinkedIn Facebook  numpy, basics
Learning Numpy - Simple Tutorial For Beginners - NumPy - Array Manipulation Part 12

Learning Numpy - Simple Tutorial For Beginners - NumPy - Array Manipulation Part 12

Several routines are available in NumPy package for manipulation of elements in ndarray object. They can be classified into the following types −

Changing Shape

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

Transpose Operations

Parameter Description
transpose Permutes the dimensions of an array
ndarray.T Same as self.transpose()
rollaxis Rolls the specified axis backwards
swapaxes Interchanges the two axes of an array

Changing Dimensions

Parameter Description
broadcast Produces an object that mimics broadcasting
broadcast_to Broadcasts an array to a new shape
expand_dims Expands the shape of an array
squeeze Removes single-dimensional entries from the shape of an array

Joining Arrays

Parameter Description
concatenate Joins a sequence of arrays along an existing axis
stack Joins a sequence of arrays along a new axis
hstack Stacks arrays in sequence horizontally (column wise)
vstack Stacks arrays in sequence vertically (row wise)

Splitting Arrays

Parameter Description
concatenate Joins a sequence of arrays along an existing axis
stack Joins a sequence of arrays along a new axis
hstack Stacks arrays in sequence horizontally (column wise)
vstack Stacks arrays in sequence vertically (row wise)

Adding / Removing Elements

Parameter Description
resize Returns a new array with the specified shape
append Appends the values to the end of an array
insert Inserts the values along the given axis before the given indices
delete Returns a new array with sub-arrays along an axis deleted
unique Finds the unique elements of an array


Dolly Solanki  Dolly Solanki