Scientific Python Glossary

Scientific Python Glossary#

Throughout this course we will use a variety of different functions available in the base Python library, but also many other libraries in the scientific computing stack. Here we provide a list of all of the functions that are used across the various notebooks. It can be a helpful reference when you are learning Python about the types of things you can do with various packages. Remember you can always view the docstrings for any function by adding a ? to the end of the function name.

Base Python Functions#

These functions are all bundled with Python

any: Test if any of the elements are true.

bool: Cast as boolean type

dict: Cast as dictionary type

enumerate: Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable.

float: Return a floating point number constructed from a number or string x.

import: Import python module into namespace.

int: Cast as integer type

len: Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

glob.glob: The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell, although results are returned in arbitrary order. No tilde expansion is done, but *, ?, and character ranges expressed with [] will be correctly matched. This is done by using the os.scandir() and fnmatch.fnmatch() functions in concert, and not by actually invoking a subshell.

list: Cast as list type

max: Return the largest item in an iterable or the largest of two or more arguments.

min: Return the smallest item in an iterable or the smallest of two or more arguments.

os.path.basename: Return the base name of pathname path. This is the second element of the pair returned by passing path to the function split(). Note that the result of this function is different from the Unix basename program; where basename for ‘/foo/bar/’ returns ‘bar’, the basename() function returns an empty string (‘’).

os.path.join: Join one or more path components intelligently. The return value is the concatenation of path and any members of paths with exactly one directory separator (os.sep) following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty. If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.

print: Print strings. Recommend using f-strings formatting. Example, print(f'Results: {variable}').

pwd: Print current working directory

sorted: Return a new sorted list from the items in iterable.

str: For more information on static methods, see The standard type hierarchy.

range: Rather than being a function, range is actually an immutable sequence type, as documented in Ranges and Sequence Types — list, tuple, range.

tuple: Cast as tuple type

type: Return the type of the object.

zip: Make an iterator that aggregates elements from each of the iterables.

NumPy#

NumPy is the fundamental package for scientific computing with Python. It contains among other things:

  • a powerful N-dimensional array object

  • sophisticated (broadcasting) functions

  • tools for integrating C/C++ and Fortran code

  • useful linear algebra, Fourier transform, and random number capabilities

Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.

import numpy as np


np.arange: Return evenly spaced values within a given interval.

np.array: Create an array

np.convolve: Returns the discrete, linear convolution of two one-dimensional sequences.

np.cos: Trigonometric cosine element-wise.

np.diag: Extract a diagonal or construct a diagonal array.

np.diag_indices: Return the indices to access the main diagonal of an array.

np.dot: Dot product of two arrays.

np.exp: Calculate the exponential of all elements in the input array.

np.fft.fft: Compute the one-dimensional discrete Fourier Transform.

np.fft.ifft: Compute the one-dimensional inverse discrete Fourier Transform.

np.hstack: Stack arrays in sequence horizontally (column wise).

np.linalg.pinv: Compute the (Moore-Penrose) pseudo-inverse of a matrix.

np.mean: Compute the arithmetic mean along the specified axis.

np.nan: IEEE 754 floating point representation of Not a Number (NaN).

np.ones: Return a new array of given shape and type, filled with ones.

np.pi: Return pi 3.1415926535897932384626433…

np.random.randint: Return random integers from low (inclusive) to high (exclusive).

np.random.randn: Return a sample (or samples) from the “standard normal” distribution.

np.real: Return the real part of the complex argument.

np.sin: Trigonometric sine, element-wise.

np.sqrt: Return the non-negative square-root of an array, element-wise.

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

np.std: Compute the standard deviation along the specified axis.

np.vstack: Stack arrays in sequence vertically (row wise).

np.zeros: Return a new array of given shape and type, filled with zeros.

Matplotlib#

Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shells, the Jupyter notebook, web application servers, and four graphical user interface toolkits.

import matplotlib.pyplot as plt


plt.bar: Make a bar plot.

plt.figure: Create a new figure.

plt.hist: Plot a histogram.

plt.imshow: Display an image, i.e. data on a 2D regular raster.

plt.legend: Place a legend on the axes.

plt.savefig: Save the current figure.

plt.scatter: A scatter plot of y vs x with varying marker size and/or color.

plt.subplots: Create a figure and a set of subplots.

plt.tight_layout: Automatically adjust subplot parameters to give specified padding.

ax.axvline: Add a vertical line across the axes.

ax.set_xlabel: Set the label for the x-axis.

ax.set_xlim: Set the x-axis view limits.

ax.set_xticklabels: Set the x-tick labels with list of string labels.

ax.set_ylim: Set the y-axis view limits.

ax.set_yticklabels: Set the y-tick labels with list of string labels.

ax.set_ylabel: Set the label for the y-axis.

ax.set_title: Set a title for the axes.