Scipy Cheat Sheet



Scientific Python Cheat Sheet Overview. This is an overview of python, numpy, scipy, matplotlib functions that are useful for scientific work. It tries to keep examples as compact as possible. Chose one of the following layouts: website; markdown; Or the print version (without pandas until there are enough commands for a third page). Python basics or Python Debugger cheat sheets for beginners covers important syntax to get started. Community-provided libraries such as numpy, scipy, sci-kit and pandas are highly relied on and the NumPy/SciPy/Pandas Cheat Sheet provides a quick refresher to these. Python 2.7 Quick Reference Sheet. You’ll see that this SciPy cheat sheet covers the basics of linear algebra that you need to get started: it provides a brief explanation of what the library has to offer and how you can use it to interact with NumPy, and goes on to summarize topics in linear algebra, such as matrix creation, matrix functions, basic routines that you can perform with matrices, and matrix decompositions from scipy.linalg. PYTHON CHEAT SHEET Python is a most popular general-purpose, high-level programming language which was created in 1991 by Guido van Rossum and developed by Python Software Foundation to concentrate on the readability of code with its extensive use of white space.

Complete List of Cheat Sheets and Infographics for Artificial intelligence (AI), Neural Networks, Machine Learning, Deep Learning and Big Data.

Content Summary

Neural Networks
Neural Networks Graphs
Machine Learning Overview
Machine Learning: Scikit-learn algorithm
Scikit-Learn
Machine Learning: Algorithm Cheat Sheet
Python for Data Science
TensorFlow
Keras
Numpy
Pandas
Data Wrangling
Data Wrangling with dplyr and tidyr
Scipy
Matplotlib
Data Visualization
PySpark
Big-O
Resources

Neural Networks

Artificial neural networks (ANN) or connectionist systems are computing systems vaguely inspired by the biological neural networks that constitute animal brains. The neural network itself is not an algorithm, but rather a framework for many different machine learning algorithms to work together and process complex data inputs. Such systems “learn” to perform tasks by considering examples, generally without being programmed with any task-specific rules.

Neural Networks Graphs

Graph Neural Networks (GNNs) for representation learning of graphs broadly follow a neighborhood aggregation framework, where the representation vector of a node is computed by recursively aggregating and transforming feature vectors of its neighboring nodes. Many GNN variants have been proposed and have achieved state-of-the-art results on both node and graph classification tasks.

Machine Learning Overview

Machine learning (ML) is the scientific study of algorithms and statistical models that computer systems use to progressively improve their performance on a specific task. Machine learning algorithms build a mathematical model of sample data, known as “training data”, in order to make predictions or decisions without being explicitly programmed to perform the task. Machine learning algorithms are used in the applications of email filtering, detection of network intruders, and computer vision, where it is infeasible to develop an algorithm of specific instructions for performing the task.

Machine Learning: Scikit-learn algorithm

This machine learning cheat sheet will help you find the right estimator for the job which is the most difficult part. The flowchart will help you check the documentation and rough guide of each estimator that will help you to know more about the problems and how to solve it.

Scikit-Learn

Scikit-learn (formerly scikits.learn) is a free software machine learning library for the Python programming language. It features various classification, regression and clustering algorithms including support vector machines, random forests, gradient boosting, k-means and DBSCAN, and is designed to interoperate with the Python numerical and scientific libraries NumPy and SciPy.

Machine Learning: Algorithm Cheat Sheet

This machine learning cheat sheet from Microsoft Azure will help you choose the appropriate machine learning algorithms for your predictive analytics solution. First, the cheat sheet will asks you about the data nature and then suggests the best algorithm for the job.

Python for Data Science

TensorFlow

In May 2017 Google announced the second-generation of the TPU, as well as the availability of the TPUs in Google Compute Engine. The second-generation TPUs deliver up to 180 teraflops of performance, and when organized into clusters of 64 TPUs provide up to 11.5 petaflops.

Keras

In 2017, Google’s TensorFlow team decided to support Keras in TensorFlow’s core library. Chollet explained that Keras was conceived to be an interface rather than an end-to-end machine-learning framework. It presents a higher-level, more intuitive set of abstractions that make it easy to configure neural networks regardless of the backend scientific computing library.

Numpy

NumPy targets the CPython reference implementation of Python, which is a non-optimizing bytecode interpreter. Mathematical algorithms written for this version of Python often run much slower than compiled equivalents. NumPy address the slowness problem partly by providing multidimensional arrays and functions and operators that operate efficiently on arrays, requiring rewriting some code, mostly inner loops using NumPy.

Pandas

The name ‘Pandas’ is derived from the term “panel data”, an econometrics term for multidimensional structured data sets.

Data Wrangling

The term “data wrangler” is starting to infiltrate pop culture. In the 2017 movie Kong: Skull Island, one of the characters, played by actor Marc Evan Jackson is introduced as “Steve Woodward, our data wrangler”.

Data Wrangling with dplyr and tidyr

Scipy

SciPy builds on the NumPy array object and is part of the NumPy stack which includes tools like Matplotlib, pandas and SymPy, and an expanding set of scientific computing libraries. This NumPy stack has similar users to other applications such as MATLAB, GNU Octave, and Scilab. The NumPy stack is also sometimes referred to as the SciPy stack.

Matplotlib

matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+. There is also a procedural “pylab” interface based on a state machine (like OpenGL), designed to closely resemble that of MATLAB, though its use is discouraged. SciPy makes use of matplotlib. pyplot is a matplotlib module which provides a MATLAB-like interface. matplotlib is designed to be as usable as MATLAB, with the ability to use Python, with the advantage that it is free.

Data Visualization

PySpark

Big-O

Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. It is a member of a family of notations invented by Paul Bachmann, Edmund Landau and others, collectively called Bachmann–Landau notation or asymptotic notation.

Resources

Big-O Algorithm Cheat Sheet
Bokeh Cheat Sheet
Data Science Cheat Sheet
Data Wrangling Cheat Sheet
Data Wrangling
Ggplot Cheat Sheet
Keras Cheat Sheet
Keras
Machine Learning Cheat Sheet
Machine Learning Cheat Sheet
ML Cheat Sheet
Matplotlib Cheat Sheet
Matpotlib
Neural Networks Cheat Sheet
Neural Networks Graph Cheat Sheet
Neural Networks
Numpy Cheat Sheet
NumPy
Pandas Cheat Sheet
Pandas
Pandas Cheat Sheet
Pyspark Cheat Sheet
Scikit Cheat Sheet
Scikit-learn
Scikit-learn Cheat Sheet
Scipy Cheat Sheet
SciPy
TesorFlow Cheat Sheet
Tensor Flow
Course Duck > The World’s Best Machine Learning Courses & Tutorials in 2020

Cheat

Tag: Machine Learning, Deep Learning, Artificial Intelligence, Neural Networks, Big Data

Related posts:

This cheat sheet is a quick reference for NumPy / SciPy beginners and gives an overview about the most important commands and functions of NumPy and SciPy that you might need on solving the exercise sheets about Linear Algebra in Information Retrieval. It doesn't claim to be complete and will be extended continuously. If you think that some important thing is missing or if you find any errors, please let us know.

Contents

  1. NumPy/SciPy Cheat Sheet
    1. General
    2. Install
    3. Matrix construction
    4. Matrix operations
    5. Useful methods
    6. Matrix decomposition

General

What is NumPy?

A library that allows to work with arrays and matrices in Python.

What is SciPy?

Another library built upon NumPy that provides advanced Linear Algebra stuff.

Install

The routine to install NumPy and SciPy depends on your operating system.

Linux (Ubuntu, Debian)

Other systems (Windows, Mac, etc.)

For all other systems (Windows, Mac, etc.) see the instructions given on the offical SciPy website.

Matrix construction

We distinguish between dense matrices and sparse matrices (Note: The color code will be used consistently throughout this cheat sheet).

Dense matrices store every entry in the matrix, while sparse matrices only store the non-zero entries (together with their row and column index). Dense matrices are more feature-rich, but may consume more memory space than sparse matrices (in particular if most of the entries in a matrix are zero).

Dense matrices

In NumPy, there are two concepts of dense matrices: matrices and arrays. Matrices are strictly 2-dimensional, while arrays are n-dimensional (the term array is a bit misleading here).

Construct a matrix:

Construct an array:

Dense

Sparse matrices

There are two principle concepts of sparse matrices:

  • Compressed Sparse Row matrix (CSR matrix): entries are stored row by row (sorted by row index first)

  • Compressed Sparse Column matrix (CSC matrix): entries are stored column by column (sorted by column index first)

Construct a CSR/CSC matrix:

Special matrices

There are some utility functions to create special matrices/arrays:

(1) Construct an empty array, without initializing the entries (an array with random entries):

Dense

(2) Construct an array filled with zeros:

(3) Construct an array filled with ones:

Dense

(4) Construct a diagonal array, a (usually square) array in which all entries are 0, except on the main diagonal:

Sparse

(5) Construct an identity array, a square array in which all entries on the main diagonal are 1 and all other entries are 0:

Sparse

(6) Construct an triangular array, a square array in which all entries below (upper triangle) or above (lower triangle) the main diagonal are zero:

Sparse

Accessing elements

TODO: crazy element access magic, single elements, entire rows, sub-matrices

Matrix operations

Adding a constant

The addition of a constant adds the constant to every element of a matrix (only available for dense matrices).

Multiplying by a constant

Multiplying by a constant multiplies every element of a matrix by that constant (both for sparse and dense matrices).

Dense

Multiplying two matrices

There are two options on multiplying two matrices: the * operator and the dot() function. The behavior and result of both options differ depending on the type of the used matrices (resp. arrays):

(1) The * operator computes

Scipy
  • the normal matrix multiplication when sparse and/or dense matrices are used.

  • the element-wise matrix multiplication when dense arrays are used.

(2) The dot() function computes

  • the normal matrix multiplication when a dense matrix is multiplied with a dense matrix or a sparse matrix is multiplied with a sparse matrix or a dense matrix;

  • bullshit when a dense matrix is multiplied with a sparse matrix.

Scipy Stats Cheat Sheet

The result of a matrix multiplication between

  • a sparse matrix and a sparse matrix is a sparse matrix.

  • a sparse matrix and a dense matrix is a dense matrix.

  • a dense matrix and a dense matrix is a dense matrix.

Useful methods

numpy.round()

Takes an array or matrix and rounds its values to the given number of decimals. Note that for values exactly halfway between rounded decimal values, numpy rounds to the nearest even value.

numpy.min()

Takes an array and returns its minimum value. If an axis is specified, returns the minima along the axis.

numpy.argmin()

Takes an array and returns the index of the minimum value of the flattened array. If an axis is specified, returns the indices of the minimum values along the axis.

numpy.argsort()

Takes an array A and returns an array of indices that sort A. Optionally, you can specify the axis along which a will be sorted.

numpy.where()

Takes a condition and optionally two array-like objects A and B. If A and B are specified, returns an array that contains elements from A where condition is true and elements from B elsewhere.

Matrix decomposition

Singular Value Decompostion (SVD)

Numpy Cheat Sheet

Factorize a matrix A (m*n) into three matrices U (m * r), S (r * r) and V (r * n) such that A = U * S * V. Here r is the rank of A.

Scipy Cheat Sheet

Dense