Numpy Cheat Sheet

Useful NumPy functions

The following table is taken from the Numpy chapter of the Python Basics course.

Command Description
Creating and manipulating arrays:  
np.arange(number) creates an array of evenly spaced values,
e.g. np.arange(3) creates an array of the numbers 1, 2, 3
np.array([1,2,3]) creates an array, e.g., of the numbers 1, 2, 3
np.shape(array) get the shape (dimensions and lengths) of array
array.dtype get the type of array (integer?, float?, …)
array.reshape reshapes array, e.g. from shape (6) to (2,3)
np.transpose or array.T transpose array
   
np.append(array1, array2) append array1 to array2
np.concatenate((array1, array2)) concatenate array1 and array2
np.insert(array, index, value) insert value at index-position of array
np.delete(array, index) delete entry at index-position of array
   
Useful statistical functions:  
np.mean(array) calculate the average of array
np.median(array) calculate the median of array
np.std(array) calculate the standard deviation of array
np.sum(array) calculate the sum of array
np.cumsum(array) calculate the cumulative sum of array
np.max(array) calculate the maximum of array
np.min(array) calculate the minimum of array
   
Useful mathematical functions:  
np.sqrt(array) calculate the square root of array
np.square(array) calculate the square of array
np.abs(array) calculate the element-wise absolute values of array
np.exp(array) calculate the exponentiation of array
np.log(array) calculate the natural logarithm of array
np.sin(array) calculate the sine of array
np.cos(array) calculate the cosine of array
   
np.round(array) round array
np.floor(array) floor of the array
np.ceil(array) ceiling of the array
np.sort(array) sort array
   
np.nan_to_num(array) replace NaN (Not a Number) with zero and
infinity with large finite numberization

updated:

1 other article is linked to this site