What Are Python Libraries / Classes / Functions / Properties

Programming a Quantum Computer

Python Libraries

  • Matplotlib: a comprehensive library for creating static, animated, and interactive visualizations in Python
  • Numpy: a fundamental package for scientific computing in Python - a Python library that provides a multidimensional array object, various derived objects, and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more
  • Pandas: a fast, powerful, flexible and easy to use open source data analysis and manipulation tool built on top of the Python programming language
  • PyTorch: an open source machine learning framework based on the Torch library used for applications such as computer vision and natural language processing - primarily developed by Facebook's AI Research lab 
  • QuTip: an open-source software for simulating the dynamics of open quantum systems 
  • SciPy: SciPy is a free and open-source Python library used for scientific computing and technical computing. SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers and other tasks common in science and engineering. SciPy is a free and open-source Python library used for scientific computing and technical computing. SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers and other tasks common in science and engineering
  • Sci-Kit: machine learning in Python - simple tools for predictive data analysis that are reusable in various contexts - built on NumPy, SciPy, and matplotlib
  • Tensorflow: a free and open-source software library for machine learning and artificial intelligence - used across a range of tasks but has a particular focus on training and inference of deep neural networks

Module

  • functools: the functools module is for higher-order functions - those functions that act on or return other functions
  • math: module that provides access to the mathematical functions
  • random: module implements pseudo-random number generators for various distributions
  • randint(): return a random integer N such that a <= N <= b - for randrange(a, b+1)
  • seed: initialize the random number generator
  • stats(): this module contains a large number of probability distributions, summary and frequency statistics, correlation functions and statistical tests, masked statistics, kernel density estimation, quasi-Monte Carlo functionality, and more

Simple Statements / Keywords

  • def: function is a block of code which only runs when it is called.
  • from: find the module specified 
  • import: finding and loading modules
  • return: leaves/exits the current function call with the expression list (or None) as return value
  • with: used to simplify exception handling

Flow Control

  • else: execute statements if the condition is False
  • for: the for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence
  • if: used to create conditional statements (if statements) that permits execution of a block of code only if a condition is True
  • pass: the pass statement does nothing - it can be used when a statement is required syntactically but the program requires no action
  • in range(): generates arithmetic progressions

Boolean Operators

  • not: yields True if its argument is false, False otherwise
  • and: x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned
  • or: x or y first evaluates x; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned 

Matplotlib Classes/Functions/Properties

  • pyplot: a state-based interface to matplotlib providing an implicit way of plotting - acts as the figure GUI manager
  • legend(): responsible for drawing legends associated with axes and/or figures
  • plot(x, y): plot y versus x as lines and/or markers
  • show(): displays all open figures
  • xlabel(): set the label for the x-axis
  • ylabel(): set the label for the y-axis
  • ylim(): get or set the y-limits of the current axes

Python Classes/Functions/Properties

  • [:]: a slice is created using the subscript notation, [] with colons between numbers when several are given - such as variable_name[1:3:5] 
  • abs(x): returns the absolute value of a number - the argument may be an integer, a floating point number, or an object implementing abs() 
  • ceil(x): returns the ceiling of x - the smallest integer greater than or equal to x
  • filter(function, iterable): construct an iterator from those elements of iterable for which function returns true 
  • format(value): convert a value to a “formatted” representation, as controlled by format_spec
  • int(x): return an integer object constructed from a number or string x, or return 0 if no arguments are given
  • lambda(): an anonymous inline function consisting of a single expression which is evaluated when the function is called - the syntax to create a lambda function is
    • lambda [parameters]: expression
      • parameter: a named entity in a function definition that specifies an argument that the function can accept - five kinds of parameter: 1) positional-or-keyword, 2) positional-only, 3) keyword-only, 4) var-positional, and 5) var-keyword - parameters can specify both optional and required arguments, as well as default values for some optional arguments
      • expression: syntax which can be evaluated to some value - an expression is an accumulation of expression elements like literals, names, attribute access, operators, or function calls which all return a value 
  • len(): return the length (the number of items) of an object
  • list(): lists are mutable sequences, typically used to store collections of homogeneous items
  • map(function, iterable): return an iterator that applies function to every item of iterable, yielding the results 
  • print(object): print objects to the text stream file
  • range(): generates arithmetic progressions
  • reduce(function, iterable): apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value 
  • reversed(seq): returns a reverse iterator - seq must be an object which has a reversed() method
  • round(n): return a number rounded to n digits precision after the decimal point - if n digits is omitted or is None, it returns the nearest integer
  • run(): the standard run() method invokes the callable object passed to the object’s constructor as the target argument 
  • sorted(iterable): returns a new sorted list from the items in iterable
  • spearman(a, b): the Spearman rank-order correlation coefficient is a nonparametric measure of the monotonicity of the relationship between two datasets - unlike the Pearson correlation, the Spearman correlation does not assume that both datasets are normally distributed - like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation - correlations of -1 or +1 imply an exact monotonic relationship - positive correlations imply that as x increases, so does y - negative correlations imply that as x increases, y decreases
  • sum(): start and the items of an iterable from left to right and returns the total
  • True: the true value of the bool type
  • uniform(a, b): return a random floating point number N such that a <= N <= b for a <= b and b <= N <= a for b < a
  • zip(iterables): iterate over several iterables in parallel, producing tuples with an item from each one

Pandas Classes/Functions/Properties

  • DataFrame():  two-dimensional, size-mutable, potentially heterogeneous tabular data.  Data structure contains labeled rows and columns
  • drop("Labels", axis=1): remove rows or columns by specifying label names and corresponding axis - drop labels from the index (0) or columns (1) 
  • dropna(subset=["label"], axis=0):  remove missing values - 0 : drop rows which contain missing values - 1 : drop columns which contain missing value
  • fillna(): fill NA/NaN values using the specified method - see mean()
  • head(): returns the first n rows for the object based on position
  • hist(bins=80): make a histogram of the DataFrame’s columns - a histogram is a representation of the distribution of data
  • iloc(): an integer-location based indexing for selection by position
  • info(): prints information about a DataFrame including the index, dtype, columns, non-null values, and memory usage
  • max(): return the largest item in an iterable or the largest of two or more arguments
  • mean(): return the mean of the values over the requested axis
  • min(): return the smallest item in an iterable or the smallest of two or more arguments
  • nunique(): count number of distinct elements in specified axis
  • open(file, mode=): open file and return a corresponding file object - mode is an optional string that specifies the mode in which the file is opened 
  • read_csv(filepath): read a comma-separated values (csv) file into DataFrame
  • shape: return a tuple representing the dimensionality (number of rows and columns) of the DataFrame
  • std(): returns a sample standard deviation over requested axis
  • tail(): returns the last n rows for the object based on position
  • tolist(): converts the array to an ordinary list with the same items

Numpy Classes/Functions/Properties

  • arange(start, stop, step): returns evenly spaced values within a given interval - values are generated within the half-open interval (the interval including start but excluding stop)  - returns an ndarray rather than a list
  • save(file, arr): save an array to a binary file in NumPy .npy format - arr is the array data to be saved

Scikit-Learn (Preprocessing) Classes/Functions/Properties

  • fit(): fit label encoder
  • LabelEncoder(): encode target labels with value between 0 and n_classes-1 
  • MinMaxScaler(): transform features by scaling and translating each feature individually to a given range - ie. between zero and one NOTE: scaler returns a Numpy-array instead of a Pandas DataFrame
  • transform(): transform labels to normalized encoding

Scikit-Learn (Metrics) Classes/Functions/Properties

  • confusion_matrix(true, predicted): compute the confusion matrix to evaluate the accuracy of a classification - a confusion matrix C is such that Ci,j is equal to the number of observations known to be in group i and predicted to be in group j - in a binary classification, the count of true negatives (TN) is C0,0, false negatives (FN) is C1,0, true positives (TP) is C1,1 and false positives (FP) is C0,1 
  • precision_score(true, predicted): the precision is the ratio TP/ (TP + FP) where TP is the number of true positives and FP is the number of false positives - said differently, precision is the ratio of TP/(All Predicted Positives) - the precision is the ability of the classifier not to label as positive a sample that is negative - the best value is 1 and the worst value is 0
  • recall_score(true, predicted): the recall is the ratio TP / (TP + FN) where TP is the number of true positives and FN is the number of false negatives - said differently, recall is the ratio of TP/(All Actual Positives) - the recall is the ability of the classifier to find all the positive samples - the best value is 1 and the worst value is 0

Scikit-Learn (Model Selection) Classes/Functions/Properties

  • train_test_split(inputs, train_size=): split arrays or matrices into random train and test subsets - allowed inputs are lists, numpy arrays, scipy-sparse matrices or pandas dataframes - train_size should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the train split