Meta tags:
Headings (most frequently used words):
and, creating, vectors, matrices, matlab, python, julia, cheatsheet, dependencies, setup, manipulating, accessing, vector, matrix, elements, mathematical, operations, sum, max, min, programming,
Text of the page (most frequently used words):
dims (17), matrix (17), sum (16), something (15), min (14), max (14), julia (12), #python (12), end (11), matlab (10), array (9), and (8), rand (8), comment (8), accumulate (8), size (8), quantecon (7), else (7), operation (7), linalg (7), reshape (7), vector (7), matrices (7), similar (6), function (6), random (6), return (6), cumsum (6), using (5), this (5), def (5), mdef (5), minimum (5), maximum (5), row (5), diag (5), zeros (5), out (4), import (4), while (4), for (4), block (4), column (4), norm (4), dot (4), the (4), vectors (4), sparse (4), ones (4), creating (4), with (3), from (3), test (3), not (3), solve (3), vec (3), val (3), det (3), inv (3), multiplication (3), ncol (3), nrow (3), diagonals (3), access (3), broadcast (3), arange (3), transpose (3), randn (3), cheatsheet (3), cheatsheets (3), created (2), inplace (2), namedtuple (2), tuples (2), anonymous (2), can (2), print (2), loop (2), range (2), one (2), programming (2), cummin (2), cummax (2), cumulative (2), each (2), when (2), eig (2), power (2), element (2), empty_like (2), possible (2), mathematical (2), operations (2), shape (2), specific (2), columns (2), rows (2), accessing (2), elements (2), functions (2), directly (2), new (2), repeat (2), times (2), dimension (2), reverse (2), flipud (2), flip (2), fliplr (2), concatenate (2), manipulating (2), tridiagonal (2), nan (2), coo_matrix (2), numbers (2), diagonal (2), eye (2), linspace (2), assume (2), you (2), compat (2), have (2), run (2), statistics (2), later (2), code (2), dependencies (2), setup (2), lectures (2), hosted, aws, sphinx, copyright, 2017, cheat, sheet, was, other, collaborators, behalf, natasha, watkins, andrij, stachurski, victoria, gregory, credits, consistent, simple, syntax, achieve, modification, closures, same, above, with_kw, parameters, constructor, vanilla, collections, named, structures, use, cells, but, watch, performance, anon, rebound, lambda, println, fprintf, text, variable, following, pep8, line, amin, amax, entire, lstsq, least, squares, problem, rectangular, linear, system, square, euclidean, eigen, eigenvalues, eigenvectors, determinant, inverse, elementwise, matrix_power, wise, mul, matmul, cdot, tab, product, get, dimensions, remove, over, collection, empty, type, preallocating, tile, repmat, down, left, right, flatten, convert, vcat, vstack, vertcat, vertically, hcat, hstack, horzcat, horizontally, conj, complex, conjugate, adjoint, toarray, diags, spdiags, spzeros, sparsearrays, scipy, normal, uniform, neighboring, 2x2, demanded, will, adopt, identity, create, length, linearly, spaced, points, integers, step, are, linearalgebra, that, already, numpy, numerical, quant, econ, twitter, repository, store, forum, blog, community, notes, library, notebooks, jupinx, datascience, quantitative, economics, documentation,
Text of the page (random words):
matlab python julia cheatsheet cheatsheets by quantecon documentation quantecon lectures lectures in quantitative economics quantecon datascience cheatsheets code quantecon py quantecon jl jupinx notebooks nb library qe notes community blog forum store repository twitter cheatsheets by quant econ numerical python julia statistics matlab python julia cheatsheet dependencies and setup creating vectors creating matrices manipulating vectors and matrices accessing vector matrix elements mathematical operations sum max min programming matlab python julia cheatsheet dependencies and setup in the python code we assume that you have already run import numpy as np in the julia we assume you are using v1 0 2 or later with compat v1 3 0 or later and have run using linearalgebra statistics compat creating vectors operation matlab python julia row vector size 1 n a 1 2 3 a np array 1 2 3 reshape 1 3 a 1 2 3 column vector size n 1 a 1 2 3 a np array 1 2 3 reshape 3 1 a 1 2 3 1d array size n not possible a np array 1 2 3 a 1 2 3 or a 1 2 3 integers from j to n with step size k a j k n a np arange j n 1 k a j k n linearly spaced vector of k points a linspace 1 5 k a np linspace 1 5 k a range 1 5 length k creating matrices operation matlab python julia create a matrix a 1 2 3 4 a np array 1 2 3 4 a 1 2 3 4 2 x 2 matrix of zeros a zeros 2 2 a np zeros 2 2 a zeros 2 2 2 x 2 matrix of ones a ones 2 2 a np ones 2 2 a ones 2 2 2 x 2 identity matrix a eye 2 2 a np eye 2 a i will adopt 2x2 dims if demanded by neighboring matrices diagonal matrix a diag 1 2 3 a np diag 1 2 3 a diagonal 1 2 3 uniform random numbers a rand 2 2 a np random rand 2 2 a rand 2 2 normal random numbers a randn 2 2 a np random randn 2 2 a randn 2 2 sparse matrices a sparse 2 2 a 1 2 4 a 2 2 1 from scipy sparse import coo_matrix a coo_matrix 4 1 0 1 1 1 shape 2 2 using sparsearrays a spzeros 2 2 a 1 2 4 a 2 2 1 tridiagonal matrices a 1 2 3 nan 4 5 6 7 nan 8 9 0 spdiags a 1 0 1 4 4 import sp sparse as sp diagonals 4 5 6 7 1 2 3 8 9 10 sp diags diagonals 0 1 2 toarray x 1 2 3 y 4 5 6 7 z 8 9 10 tridiagonal x y z manipulating vectors and matrices operation matlab python julia transpose a a t transpose a complex conjugate transpose adjoint a a conj a concatenate horizontally a 1 2 1 2 or a horzcat 1 2 1 2 b np array 1 2 a np hstack b b a 1 2 1 2 or a hcat 1 2 1 2 concatenate vertically a 1 2 1 2 or a vertcat 1 2 1 2 b np array 1 2 a np vstack b b a 1 2 1 2 or a vcat 1 2 1 2 reshape to 5 rows 2 columns a reshape 1 10 5 2 a a reshape 5 2 a reshape 1 10 5 2 convert matrix to vector a a a flatten a flip left right fliplr a np fliplr a reverse a dims 2 flip up down flipud a np flipud a reverse a dims 1 repeat matrix 3 times in the row dimension 4 times in the column dimension repmat a 3 4 np tile a 4 3 repeat a 3 4 preallocating similar x rand 10 y zeros size x 1 size x 2 n a similar type x np random rand 3 3 y np empty_like x new dims y np empty 2 3 x rand 3 3 y similar x new dims y similar x 2 2 broadcast a function over a collection matrix vector f x x 2 g x y x 2 y 2 x 1 10 y 2 11 f x g x y functions broadcast directly def f x return x 2 def g x y return x 2 y 2 x np arange 1 10 1 y np arange 2 11 1 f x g x y functions broadcast directly f x x 2 g x y x 2 y 2 x 1 10 y 2 11 f x g x y accessing vector matrix elements operation matlab python julia access one element a 2 2 a 1 1 a 2 2 access specific rows a 1 4 a 0 4 a 1 4 access specific columns a 1 4 a 0 4 a 1 4 remove a row a 1 2 4 a 0 1 3 a 1 2 4 diagonals of matrix diag a np diag a diag a get dimensions of matrix nrow ncol size a nrow ncol np shape a nrow ncol size a mathematical operations operation matlab python julia dot product dot a b np dot a b or a b dot a b a b cdot tab matrix multiplication a b a b a b inplace matrix multiplication not possible x np array 1 2 reshape 2 1 a np array 1 2 3 4 y np empty_like x np matmul a x y x 1 2 a 1 2 3 4 y similar x mul y a x element wise multiplication a b a b a b matrix to a power a 2 np linalg matrix_power a 2 a 2 matrix to a power elementwise a 2 a 2 a 2 inverse inv a or a 1 np linalg inv a inv a or a 1 determinant det a np linalg det a det a eigenvalues and eigenvectors vec val eig a val vec np linalg eig a val vec eigen a euclidean norm norm a np linalg norm a norm a solve linear system ax b when a is square a b np linalg solve a b a b solve least squares problem ax b when a is rectangular a b np linalg lstsq a b a b sum max min operation matlab python julia sum max min of each column sum a 1 max a 1 min a 1 np sum a 0 np max a 0 np min a 0 sum a dims 1 maximum a dims 1 minimum a dims 1 sum max min of each row sum a 2 max a 2 min a 2 np sum a 1 np max a 1 np min a 1 sum a dims 2 maximum a dims 2 minimum a dims 2 sum max min of entire matrix sum a max a min a np sum a np amax a np amin a sum a maximum a minimum a cumulative sum max min by row cumsum a 1 cummax a 1 cummin a 1 np cumsum a 0 np maximum accumulate a 0 np minimum accumulate a 0 cumsum a dims 1 accumulate max a dims 1 accumulate min a dims 1 cumulative sum max min by column cumsum a 2 cummax a 2 cummin a 2 np cumsum a 1 np maximum accumulate a 1 np minimum accumulate a 1 cumsum a dims 2 accumulate max a dims 2 accumulate min a dims 2 programming operation matlab python julia comment one line this is a comment this is a comment this is a comment comment block comment block block comment following pep8 comment block for loop for i 1 n do something end for i in range n do something for i in 1 n do something end while loop while i n do something end while i n do something while i n do something end if if i n do something end if i n do something if i n do something end if else if i n do something else do something else end if i n do something else so something else if i n do something else do something else end print text and variable x 10 fprintf x d n x x 10 print f x x x 10 println x x function anonymous f x x 2 f lambda x x 2 f x x 2 can be rebound function function out f x out x 2 end def f x return x 2 function f x return x 2 end f x x 2 not anon tuples t 1 2 0 test t 1 can use cells but watch performance t 1 2 0 test t 0 t 1 2 0 test t 1 named tuples anonymous structures m x 1 m y 2 m x from collections import namedtuple mdef namedtuple m x y m mdef 1 2 m x vanilla m x 1 y 2 m x constructor using parameters mdef with_kw x 1 y 2 m mdef same as above m mdef x 3 closures a 2 0 f x a x f 1 0 a 2 0 def f x return a x f 1 0 a 2 0 f x a x f 1 0 inplace modification no consistent or simple syntax to achieve this def f x x 2 return x np random rand 10 f x function f out x out x 2 end x rand 10 y similar x f y x credits this cheat sheet was created by victoria gregory andrij stachurski natasha watkins and other collaborators on behalf of quantecon copyright 2017 quantecon created using sphinx 5 0 2 hosted with aws
|