@cocalc/static
Version:
CoCalc's static frontend Webpack-based build system and framework
1 lines • 323 kB
JavaScript
"use strict";(self.webpackChunk_cocalc_static=self.webpackChunk_cocalc_static||[]).push([[5544],{58822:e=>{e.exports=JSON.parse('{"bash":{"Git":{"Basics":{"entries":[["Status",["git status","List the modified files in the working set."]],["Diff",["git diff","Show the current changes you have done with the working set."]],["Add",["git add -A","Add all changes, including new files, to the working set. Otherwise, just pick the file for which you want to add the changes."]],["Commit",["git commit","After you have added changes, this creates a new changeset in the Git repository."]],["Push",["git push","When you have a configured remote repository with a tracking branch, this command uploads your changes to the remote repository."]]],"sortweight":0}},"Introduction":{"Basic Commands":{"entries":[["Directory Listing",["ls","lists all files in the current directory"]],["Current Directory",["pwd","**p**rints the current **w**orking **d**irectory."]],["Memory Usage (RAM)",["smem -t","Lists running processes and their memory consumption. In particular, the sum of `RSS` memory is relevant, for how much it is currently being used!"]]],"sortweight":-1}},"Language":{"Basics":{"entries":[["Variables",["foo=\'value one\'\\necho \\"this is $foo\\"","Bash uses variables to store data in a handler, which can be inserted into a statement later.\\n\\nFor storing data, it is important to **not** have any spaces around the equal sign.\\n\\nRetrieving (inserting) the data works via the `$`-sign and if in quotes, use double quotes!"]],["Function",["function f1() {\\n echo \\"$1 $2\\"\\n}\\nf1 a b\\nf1 foo","A Bash-function takes an arbitrary number of arguments and processes them.\\n\\nThe example here defines a function `f1` and prints them via `echo`.\\nNotice, that missing arguments are more-or-less like an empty string."]]],"sortweight":0}}},"cython":{},"gap":{"Arithmetic":{"Rings":{"entries":[["Integers and Rationals",[["25+17/29;","(25+17)/29;","2^257-1;","QuotientRemainder(230,17);"],"The most natural rings are\\nthe integers and the rationals. Arithmetic for these rings in GAP is a\\nrather obvious, rational numbers are represented as quotients of integers in\\ncanceled form. GAP implements integers of arbitrary length, there is no\\nneed to worry about data types as different internal representations are\\ninvisible (and unimportant) to the user."]],["Primes",[["IsPrime(7);","IsPrime(8);","NextPrimeInt(2^20);","Factors(2^51-1);"],"GAP can test primality of integers using `IsPrime` (the primality\\ntest built-in is likely good enough for any teaching application, though it\\ncannot compete with systems specific to number theory for extremely huge\\nnumbers.) As with all primality tests, the system initially does\\nprobabilistic primality test, which has been verified to be correct only up\\nto some bound ($10^{13}$ as of the time of writing), even though no larger\\ncounterexample is known. GAP will print a warning, if a number is\\nconsidered prime because of this test, but not verified.\\n\\nFunctions `NextPrimeInt` and `PrevPrimeInt` return the first\\nprime larger, respectively smaller than a given number.\\n\\nThe command `Factors` returns a list of prime factors of an integer.\\n(The package `factint`, installed by default, improves the\\nfactorization functionality.) Again factorization performance is likely good\\nenough for teaching applications but not competitive with research problems."]],["Complex Numbers and Cyclotomics",[["(2+E(4))^2;","E(3)+E(3)^2;","ComplexConjugate(E(7)^2);","1/((1+ER(5))/2);"],"GAP does not have real or complex numbers. The reason is that exact\\ncomputation (which GAP guarantees) with irrationals is in general\\nextremely hard.\\n\\nGAP however supports cyclotomic fields, and in fact most examples of\\nfield extensions encountered in an introductory course (for example any\\nquadratic extension of the rationals) embed into an\\nappropriate cyclotomic field. Here `E(n)` represents a primitive\\n$n$-th root of unity. If embedding in the complex numbers is desired, one\\nmay assume that $\\\\displaystyle \\\\texttt{E(n)}=e^{\\\\frac{2\\\\pi i}{n}}=\\\\zeta_n$.\\nThus for\\nexample $E(4)$ is the complex root of $-1$. The field $\\\\Q(\\\\zeta_n)$ is\\ndenoted by `CF(n)`.\\n\\nThe command `ComplexConjugate(x)` can be used to determine the complex conjugate of a\\ncyclotomic number."]],["Quadratic Extensions of the Rationals",[["ER(3);","1+ER(3);","(1+ER(2))^2-2*ER(2);"],"Because any quadratic irrationality is cyclotomic, the function\\n`ER(n)` represents $\\\\sqrt{n}$ as cyclotomic number."]],["Greatest common divisors and Factorization",[["Gcd(192,42);","ShowGcd(192,42);","a:=GcdRepresentation(192,42)","a[1]*192+a[2]*42"],"The gcd of two numbers can be computed with `Gcd`. The teaching function\\n`ShowGcd performs the extended euclidean algorithm, displaying also\\nhow to express the gcd as integer linear combination of the original\\narguments.\\n\\n`GcdRepresentation` returns a list $[s,t]$ of the \\nthe coefficients from the extended euclidean algorithm."]],["Modulo Arithmetic",["3/2 mod 5;","The `mod`-operator can be used in general for arithmetic in the\\nquotient ring.\\nWhen applied to a quotient of elements, it automatically tries to invert the\\ndenominator, using the euclidean algorithm.\\n\\nContrary to systems such as Maple, `mod` is an ordinary\\nbinary operator in GAP and does not change the calculation done before, i.e.\\ncalculating `(5+3*19) mod 2` first calculates `5+3*19` over the\\nintegers, and then reduces the result. If intermediate coefficient growth is\\nan issue, arguments (and intermediate results) have to be reduced always\\nwith `mod`, e.g. (in the most extreme case) `(5 mod 2)+((3 mod\\n2)*(19 mod 2)) mod 2`.\\nThe function `PowerMod(base,exponent,modulus)`\\ncan be used to calculate $a^b\\\\bmod{m}$ with intermediate reduction."]]],"sortweight":0}},"Files":{"Reading and Writing Files":{"entries":[["File Operations",["","For documenting system interactions, transferring results, as well as for\\npreparing programs in a file, it is convenient to have the system read from\\nor write to files. Such files typically will be plain text files, though\\nGAP itself does not insist on using a specific suffix to indicate the\\nformat."]],["Files and Directories",[["dir:=Directory(\\"/Users/xyrxmir/gapstuff\\");","Filename(dir,\\"stuff\\");","Filename(dir,\\"stuffdir/one\\");"],"A filename in {\\\\GAP} is simply a string indicating the location of the file,\\nsuch as `\\"/Users/xyrxmir/Documents/gapstuff/myprogram\\"` or `\\"/cygdrive/c/Documents and Settings/Administrator/Desktop/myprogram\\"`.\\n\\nWe note that -- regardless of the operating system convention -- directories\\nin a path are always separated by a forward slash /, also under Windows --\\nan inheritance of the cygwin environment used to run `GAP` -- a drive\\nletter `X:` is replaced by `/cygdrive/x/`, i.e.\\n`/cygdrive/c/` is the root directory of the system drive.\\n\\nDirectories are simply shortcuts to particular paths. A directory is created\\nby `Directory(path)`. Then\\n`Filename(directory,filename)` simply produces a string\\neading with the path of `directory`. (`filename` does not need to\\nbe a simple file, but actually could include further subdirectories.)\\nNeither `Directory`, nor `Filename` check whether the file\\nexists."]],["Input and Output",[["logfile:=Filename(DirectoryDesktop(),\\"mylog\\");","LogTo(logfile); # Logging can be stopped by giving no argument to the function."],"The command `PrintTo(filename,...)` works like `Print`,\\nbut prints the output in the file specified by `filename`. The file is\\ncreated if it did not exist before and any existing file is overwritten. \\n\\n`AppendTo(filename,...)` does the same, but appends the output to an existing file.\\n\\nGAP can read input using the `Read(filename)` command. The\\ncontents of the file are read in **as if the contents were typed into\\nthe system** (just not printing out the results of commands). In particular,\\nto read in objects to GAP it is necessary to have lines start with a\\nvariable assignment and end with a semicolon. As with typing, line breaks\\nare typically not relevant.\\n\\nThe most frequent use of `Read` is to prepare GAP programs in a\\ntext editor and then read them into the system -- this provides far better\\nediting facilities than trying to write the program directly in the system,\\nsee `File Input` below.\\n\\nA special form of output is provided by the commands\\n\\n* `LogTo(\\\\gvar{filename})`\\n* `LogInputTo(\\\\gvar{filename})`\\n* `LogOutputTo(\\\\gvar{filename})`\\n\\nwhich produce a transcript of a system session (respectively only input or\\noutput) to the specified file."]],["File Input",[["Read(Filename(DirectoryHome(),\\"PerfectNumbers.g\\"));","PerfectNumber(6);"],"Often one wants to write more complicated pieces of code and save them for\\nuse later. In this situation it is useful to use your favorite text editor\\nto create a file that GAP can then read. (Caveat: The file must be a\\nplain text file, often denoted by a suffix `.txt`.\\n\\nFiles can be saved elsewhere, but then\\neither the relative path from the root directory or the absolute path must\\nbe typed into the `Read` command.\\n\\nFor example, suppose the following code is in a file named `PerfectNumbers.g`\\nin ones home directory:\\n\\n```\\n PerfectNumber:=function(n)\\n local sigma;\\n sigma:=Sum(DivisorsInt(n));\\n if sigma>2*n then \\n Print(n,\\" is abundant\\");\\n elif sigma = 2*n then\\n Print(n,\\" is perfect\\");\\n else\\n Print(n,\\" is deficient\\");\\n fi;\\n end;\\n```\\nNow we can type the command:"]]],"sortweight":0}},"Introduction":{"Basics":{"entries":[["Welcome to GAP",["for i in [1..13] do\\n # Comment\\n Print(\\"The number of divisors of 2^\\",i,\\"-1 is \\",Length(DivisorsInt(2^i-1)),\\"\\\\n\\");\\nod;","GAP is a system for computational discrete algebra, with particular emphasis on\\nComputational Group Theory. GAP provides a programming language, a library of thousands\\nof functions implementing algebraic algorithms written in the GAP language as well as large\\ndata libraries of algebraic objects."]],["Lists",[["L := [11,13,17];","L[1];","Length(L);","Position(L,13);","4 in L;","Add(L, 4);","4 in L;","Append(L,[1,2,3]);\\nPrint(L);"],"One can group several pieces of data together into one package containing all the data by creating\\na list. A list is started with a left square bracket, `[`, ended with a right square bracket, `]`,\\nand entries are separated by commas.\\n\\nIn GAP, lists are 1-indexed (as opposed to Python/Sage which are 0-indexed)."]],["Sublists of Lists",[["L := [7,11,3];","L{[1,2]};"],"Given a list `L`, we can create a sublist by using the `{}` syntax and giving a set of indices\\nof `L`."]],["List Ranges",[["L := [10 .. 20];","L{[2,4 .. 8]}"],"A special case of lists are ranges that can be used to store arithmetic progressions in a compact\\nform. The syntax is [start..end] for increments of 1, respectively [start,second..end] for\\nincrements of size second-start."]],["List Gotchas",[["L1 := [2,4, .. 10];","L2 := L1;","L1[2] := 3;","Print(L2);"],"Lists themselves are pointers to lists, assigning a list to two variables does not make a copy\\nand changing one of the lists will change the other. You can make a new list with the same entries\\nusing `ShallowCopy`."]],["Vectors and Matrices",[["vec:=[-1,2,1];","M:=[[1,2,3],[4,5,6],[7,8,9]];","vec*M;","M*vec;","M[3][2];","\\"vec*vec; # inner product\\"","Display(M);"],"Vectors in GAP are simply lists of field elements and matrices are simply\\nlists of their row vectors, i.e. lists of lists. (Thus matrix entries can be\\naccessed as M[row][column].)\\n\\nWhile vectors in GAP are usually considered as row vectors,\\nscalar products or matrix/vector products\\nautomatically consider the second factor as column vector."]],["Sets and sorted lists",[["L := Set([5,2,8,9,-3]);","AddSet(L,4);L;","Union(L,[3..6]);","Intersection(L,[3..6]);","Difference(L,[3..6]);"],"Sorted lists (in general GAP implements a total ordering via `<`\\non all its objects, though this ordering is sometimes nonobvious for more\\ncomplicated objects) are used to represent sets in GAP. For a list\\n`L`, the command `Set(L)` will return a sorted copy.\\nElement test in sets also used the `in` operator, but internally then\\ncan use binary search for a notable speedup. The same holds for\\n`Position`.\\n\\nMaintaining the set property, `AddSet(L,x)` will insert `x`\\ninto `L` at the appropriate position to maintain sortedness.\\n`Union(L,L2)` and `Intersection(L,L2)` perform the set\\noperations indicated by their name, `Difference(L,L2)` is the set\\ntheoretic difference."]],["List Operations",[["List([1..10],x->x^2);","Filtered([1..10],IsPrime);","Number([1..10],IsPrime);"],"GAP contains powerful list operations that often can be used to implement\\nsimple programming tasks in a single line. The typical format for these\\noperations is to give as arguments a list `L` and a function\\n`func` that is to be applied to the entries. These functions often\\nare given in the shorthand form `x->expr(x)`, where\\n`expr(x)` is an arbitrary GAP expression, involving `x`.\\n\\n* `List(L,func)` applies `func` to all entries of `L` and returns the list of results.\\n* `Filtered(L,func)` returns the list of those elements of `L`, for which `func` returns true.\\n* `Number(L,func)` returns the number of elements of `L`, for which `func` returns true.\\n* `First(L,func)` returns the first element of `L` for which `func` returns true.\\n* `ForAll(L,func)` returns true if `func` returns true for all entries of `L`.\\n* `ForAny(L,func)` similarly returns true if `func` returns true for at least one entry of `L`.\\n* `Collected(L)` returns a statistics of the elements of `L` in form of a list with entries `[object,count]`.\\n* `Sum(L)` takes the sum of the entries of `L`. The variant `Sum(L,func)` sums over the results of `func`,\\napplied to the entries of `L`.\\n* `Product(L)` takes the product of the entries of `L`. Again `Product(L,func)` applies func to the\\nentries of `L` first."]],["For Loops",["for i in [1..13] do\\n Print(\\"The number of divisors of 2^\\",i,\\"-1 is \\",Length(DivisorsInt(2^i-1)),\\"\\\\n\\");\\nod;","The basic loop is a for loop. Typically it will repeat some instructions as a variable iterates\\nthrough all members of a list. The instructions begin with the word `do` and end with `od`."]],["If Statments",["PerfectNumber:=function(n)\\n local sigma;\\n sigma:=Sum(DivisorsInt(n));\\n if sigma>2*n then\\n Print(n,\\" is abundant\\\\n\\");\\n elif sigma = 2*n then\\n Print(n,\\" is perfect\\\\n\\");\\n else\\n Print(n,\\" is deficient\\\\n\\");\\n fi;\\nend;","A conditional statement begins with `if`, followed by a boolean, the word then, and a set of\\ninstructions, and is finished with `fi`. The instructions are executed if and only if the boolean\\nevaluates to true. Additional conditions and instructions may be given with the `elif` (with further\\nconditions) and `else` (with no further conditions) commands."]],["More Checksum Digits",[["CheckDigitISBN13(\\"978052166103\\");","CheckDigitISBN13(\\"9781420094527\\");","CheckDigitUPC(\\"071641830011\\");","CheckDigitUPC(\\"07164183001\\");","CheckDigitPostalMoneyOrder(1678645715);"],"`CheckDigitISBN13` computes the newer ISBN-13. (The relation to old\\nISBN is to omit the original check digit, prefix 978 and compute a new check\\ndigit with multiplcation factors 1 and 3 only for consistency with UPC\\nbar codes.)\\n\\n`CheckDigitUPC` computes checksums for 12-digit UPC codes as used in\\nmost stores.\\n\\n`CheckDigitPostalMoneyOrder` finally works on 11-digit numbers for\\n(US mail) postal money orders.\\n\\nSimilar checksum schemes that check $\\\\sum_{i=1}^n c_i a_i\\\\cong 0\\\\pmod{m}$ for a\\nnumber $a_1,a_2,\\\\ldots,a_n$ ($a_n$ being the check digit) and coefficients\\n$c_i$ (i.e. for the 10 digit ISBN, the coefficients are $[ 1, 2, 3, 4, 5, 6,\\n7, 8, 9, -1 ]$) can be created using the function\\n`CheckDigitTestFunction(n,modulus,clist)`, where `clist`\\nis a list of the $c_i$. i.e. `CheckDigitISBN` is defined as\\n```\\nCheckDigitISBN:=CheckDigitTestFunction(10,11,[1,2,3,4,5,6,7,8,9,-1]);\\n```"]]],"sortweight":0}}},"javascript":{"Advanced":{"Asynchronous code":{"entries":[["Asynchronous code in ijavascript",["$$.async();\\n\\nconsole.log(\\"Hello, World!\\");\\n\\nfunction run() {\\n console.log(\\"I\'m done waiting a second.\\");\\n $$.done();\\n}\\n\\nsetTimeout(run, 1000);","This is how you can run asynchronous code in `ijavascript`. Notice, how there is a 1 second delay between the outputs and only then the execution halts (calling `$$.done()`)\\nSee [ijavascript async output](http://n-riesco.github.io/ijavascript/doc/async.ipynb.html) for more information."]]],"sortweight":0}},"Tutorial":{"Arrays":{"entries":[["Arrays",["[1, 2, 5, 10]","An array is an ordered collection of objects."]],["Array manipulations",[["let arr = [\'foo\', \'bar\', \'baz\']\\narr[1] = \'apple\'\\narr","arr[0]"],"This is how you can change an element in an array and extract an element at a specific location.\\nThe first element is at *index position 0*!"]]],"sortweight":0},"First Steps":{"entries":[["Introduction",[["// a simple calculation\\n1+1","// the version of Node.js\\nprocess.version"],"This jupyter kernel runs JavaScript remotely in Node.js.\\n- [kernel ijavascript](https://github.com/n-riesco/ijavascript) - [node.js](https://nodejs.org/en/)"]],["Variables",[["// define x\\nlet x = 20\\nx","// now refer to x in a calculation\\n2 * x + 1"],"Use the equal sign to name an object to refer to it later. `let` tells JavaScript, that this is a new variable."]],["Print output",["console.log(\\"Hello, World!\\");\\nconsole.log(9 * 9);\\nconsole.log(\\"finished\\");","Use `console.log(...)` to show output – otherwise, only the last value in a cell will be displayed."]]],"sortweight":-1},"Functions":{"entries":[["Introduction",[["function foo(x) {\\n return 2*x+1;\\n}","foo(20)"],"A JavaScript function is ..."]],["Function passing",[["function f1(x) {\\n return 2 * x + 1;\\n}","function bar(func, arg) {\\n let y = 1 + func(arg) + func(arg + 1)\\n return y;\\n}","bar(f1, 3)"],"A function is passed to another one as an argument. Try playing around with this example to really understand what\'s going on!"]]],"sortweight":0},"Iterations":{"entries":[["for-loop",[["let sum = 0;\\nfor (let i = 0; i < 10; i++) {\\n sum += i;\\n}\\nsum;"],"A for-loop iterates a value over a block of code."]]],"sortweight":0}}},"julia":{"Tutorial":{"First Steps":{"entries":[["Introduction",["# this is a comment and the next line calculates the sum of two vectors\\n[2 3] + [-1 7]","Some sources for introductions to Julia:\\n\\n* https://julialang.org/learning/\\n* https://en.wikibooks.org/wiki/Introducing_Julia"]],["Print",[["println(\\"Hello\\", 99)","x = 10\\nprintln(\\"Interpolation $(5 + x)\\")"],"You can print to standard output almost anything.\\nOne way to interpolate a string via the `$(...)` syntax."]],["Printf",["using Printf\\n@printf(\\"pi = %.7f\\\\n\\", float(pi))","This examples shows the [`@printf` macro](https://docs.julialang.org/en/v1.1/stdlib/Printf/),\\nfor C-style formatting.\\nThe line `using Printf` loads that package and makes all functions and macros available in the current session."]],["Calling a Function",["sin(3.14)","Use round brackets, multiple arguments are separated by commas."]],["Expressions",["3 + (1 - 5.5) / 2","An assignment happens by evaluating the expression on the right side after an `=` sign.\\nSo, in order to master Julia, you need to know how evaluating an expression works!"]],["Assignments",["a = 1 + 2 + 3\\nb = a / 10\\nc = a + b\\nprintln([a b c])","On the left of the equal sign are variables.\\nYou can interpret them as \\"name tags\\" for the evaluated expressions on the right.\\nLater, you can use these names to reference the results and build up more expressions.\\n\\nPlay with the following lines of code to get a feeling for what\'s going on."]],["Conditionals",["x = 4\\nif x > 0\\n println(\\"x above zero\\")\\nelseif x < 0\\n println(\\"x below zero\\")\\nelseif x == 0\\n println(\\"x exactly zero\\")\\nelse\\n println(\\"I don\'t understand what x is\\")\\nend","It\'s very common to only evaluate a part of a code under a certain condition.\\nThis is done via an \\"if\\"-statement.\\nAgain, play with the value of x to get a feeling of what\'s happening.\\n\\nPro-tipp: set `x = NaN` to trigger the last case.\\nThis stands for \\"Not a Number\\" and is commonly used to signal that there is no known value (e.g. missing results during an experiment)"]],["Loops",["using Printf\\ns = 0\\nfor i = [1 2 5 100 -1 5]\\n s = s + i\\n @printf(\\"i = %4d → s = %4d\\\\n\\", i, s)\\nend","Here is the other common building block for programming:\\nEvaluating a block of code more than once, e.g. by either counting the iterations or until a condition is met (or no longer met).\\nThis is one of the most confusing parts of programming.\\nSo don\'t be shy to take your time inspecting this.\\nTry to evaluate this little program in your head by reading the lines over and over again..."]],["Function",["function f1(a::Int)\\n return 2*a\\nend\\nfunction f1(a::Float64)\\n return -3*a\\nend\\n\\nprintln(f1(10))\\nprintln(f1(2.0))","A function is a very important and fundamental building block in the Julia language.\\nIt transforms a set of inputs to a result.\\nMost importantly, several functions can have the same name -- and they\'re selected based on the types of the input."]]],"sortweight":0}}},"octave":{"Applied Mathematics":{"Optimization":{"entries":[["Numerical Optimization",["pkg load optim;\\n\\nfunction [obj_value, gradient] = objective(theta, location)\\n x = theta - location + ones(rows(theta),1); # move minimizer to \\"location\\"\\n [obj_value, gradient] = rosenbrock(x);\\nendfunction\\n\\ndim = 20; # dimension of Rosenbrock function\\ntheta0 = zeros(dim+1,1); # starting values\\nlocation = (0:dim)/dim; # true values\\nlocation = location\';\\ncontrol = {Inf,1}; # maxiters, verbosity\\n\\nbfgsmin(\\"objective\\", {theta0, location}, control);","You can run numerical optimizations via the [optim](https://octave.sourceforge.io/optim/package_doc/index.html) package.\\n\\nIn this example we minimize the classical Rosenbrock function in 20 dimensions using BFGS."]]],"sortweight":0}},"Functions":{"Utilities":{"entries":[["Linspace",["linspace(-2, 5, 20)\'","`linspace` creates a one dimensional (*linear*) array of equally spaced values.\\n\\nThe `\'` tickmark transposes it to a vector, which is the usual form when further using it in a calculation."]],["Meshgrid",["x = 0:3;\\ny = 0:4;\\n[xx, yy] = meshgrid(x, y);\\nxx + 2*yy","Imagine you want to evaluate a binary function $f(x,\\\\,y) := x + 2 y$.\\n\\nFor evaluating it in vectorized notation, you need a grid for the cartesian product of all $x$ and $y$."]]],"sortweight":0}},"Introduction":{"First Steps":{"entries":[["Elementary Calculations",["exp (i*pi)","Octave can easily be used for basic numerical calculations. Octave knows about arithmetic operations (+,-,*,/), exponentiation (^), natural logarithms/exponents (log, exp), and the trigonometric functions (sin, cos, …). Moreover, Octave calculations work on real or imaginary numbers (i,j). In addition, some mathematical constants such as the base of the natural logarithm (e) and the ratio of a circle’s circumference to its diameter (pi) are pre-defined.\\n\\nFor example, to verify Euler’s Identity,\\n\\n$$e^{\\\\mathbb{i} * \\\\pi} = -1$$\\n\\ntype the following which will evaluate to -1 within the tolerance of the calculation."]],["Creating a Matrix",["A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]\\nB = rand(3, 2);\\nB","Vectors and matrices are the basic building blocks for numerical analysis. To create a new matrix and store it in a variable so that you can refer to it later.\\nOctave will respond by printing the matrix in neatly aligned columns. Octave uses a comma or space to separate entries in a row, and a semicolon or carriage return to separate one row from the next. Ending a command with a semicolon tells Octave not to print the result of the command. For example,"]],["Matrix Arithmetic",["A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ];\\nB = rand(3, 2);\\n2 * A\\nA * B\\nA\' * A\\nA .* A","Octave has a convenient operator notation for performing matrix arithmetic.\\nFor example, to multiply the matrix A by a scalar value, type the command: `2 * A`.\\n\\nTo multiply the two matrices A and B, type the command `A * B`\\n\\nand to form the matrix product `transpose(A) * A`, type the command `A\' * A`\\n\\nFinally, elementwise operations are done via a dot, e.g. `A .* A`."]],["Solving Systems of Linear Equations",["A = [ 2, 0; 0, 2 ];\\nb = [ 2; 1 ];\\nx = A \\\\ b","To solve the set of linear equations Ax = b, use the left division operator, ‘\\\\’"]],["Integrating Differential Equations",["function xdot = f (x, t)\\n r = 0.25;\\n k = 1.4;\\n a = 1.5;\\n b = 0.16;\\n c = 0.9;\\n d = 0.8;\\n xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));\\n xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);\\nendfunction\\n\\nx0 = [1; 2];\\n\\nt = linspace (0, 50, 200)\';\\n\\nx = lsode (\\"f\\", x0, t);\\n\\nx","Octave has built-in functions for solving nonlinear differential equations.\\nYou must first provide a definition of the function f(x,t), the initial condition $t_0$,\\nand the set of output times as a column vector $t$ (note that the first output time corresponds to the initial condition given above)."]],["Producing Graphical Output",["t = -5:0.1:5;\\nx = 2 - (t - 4).^2 .* (t + 3).^3;\\nplot (t, x)","Octave is capable of creating various types of plots. Here we show the plot of\\n\\n$$x(t) := 2 - (t - 4)^2 (t + 3)^3$$\\n\\nfor $t \\\\in \\\\left[-5, 5\\\\right]$. Look into the section named \\"Visualization\\" to see find more examples..."]],["Help and Documentation",["help plot","You can find this introcution guide online: https://www.gnu.org/software/octave/doc/v4.0.3/Simple-Examples.html\\n\\nYou can also use the help command"]]],"sortweight":0}},"Visualization":{"2D Plots":{"entries":[["Simple 2-D Plot",["x = 0:0.01:20;\\ny = (1 + sqrt(x)) .* sin (x);\\nplot (x, y);\\nxlabel (\\"x\\");\\nylabel (\\"(1 + sqrt(x)) * sin (x)\\");\\ntitle (\\"Simple 2-D Plot\\");","This is a simple 2 dimensional plot in Octave.\\nA vector `x` is mapped via $(1 + \\\\sqrt{x}) * \\\\sin(x)$ to another vector of equal length.\\nThen, `plot(x, y)` visualizes that dependenc.\\n\\nReference: [2D Plotting in the Octave documentation](https://octave.org/doc/v4.2.2/Two_002dDimensional-Plots.html)"]],["Histogram",["a = 1.1 * randn(10000, 1) - 6;\\nb = 3 * randn(30000, 1) + 1;\\nhist ([a; b], 30);\\nxlabel (\\"Value\\");\\nylabel (\\"Count\\");\\ntitle (sprintf(\\"Histogram of %d normally distributed random numbers\\", length(a) + length(b)));","This is a classical way to visualize a statistical distribution.\\nWe take a look at the sum of two samples ...\\n\\nReference: [Histogram in 2D plotting manual](https://octave.org/doc/v4.2.2/Two_002dDimensional-Plots.html)"]],["Function plotting",["fplot (@(x) cos(x) .* sin(2*x), [0, 2*pi])","$$f(x) := \\\\cos(x) \\\\sin(2 x)\\\\;\\\\text{for}\\\\;x \\\\in \\\\left[0,\\\\,2 \\\\pi\\\\right]$$\\n\\n> Octave can plot a function from a function handle, inline function, or string defining the function without the user needing to explicitly create the data to be plotted.\\n\\n-- [Reference about plotting functions](https://octave.org/doc/v4.2.2/Two_002ddimensional-Function-Plotting.html#Two_002ddimensional-Function-Plotting)"]],["Implicit relationship",["ezplot (@(x, y) x.^2 + 3 * (y - 1).^2 + .5 * x .* y - 6)","This draws the set of points, where the given equation is satisfied.\\nHere, it shows a tilted ellipse.\\n\\n$$x^2 + 3 (y-1)^2 + \\\\frac{x y}{2} = 6$$\\n\\nReference: [ezplot](https://octave.org/doc/v4.2.2/Two_002ddimensional-Function-Plotting.html#Two_002ddimensional-Function-Plotting)"]]],"sortweight":0},"3D Plots":{"entries":[["Mesh Plot",["tx = ty = linspace (-8, 8, 41)\';\\n[xx, yy] = meshgrid (tx, ty);\\nr = sqrt (xx .^ 2 + yy .^ 2) + eps;\\ntz = sin (r) ./ r;\\nmesh (tx, ty, tz);\\nxlabel (\\"tx\\");\\nylabel (\\"ty\\");\\nzlabel (\\"tz\\");\\ntitle (\\"3-D Sombrero plot\\");","This plot shows the famous 3D sombrero.\\n\\nA quadratic meshgrid of $x$ and $y$ coordinates is evaluated via $\\\\sqrt{x^2 + y^2} + \\\\epsilon$ and the value $r$ is then the value plotted along the third dimension.\\n\\nReference: [3d plots](https://octave.org/doc/v4.2.2/Three_002dDimensional-Plots.html#Three_002dDimensional-Plots)"]]],"sortweight":0}}},"python":{"Data Analysis":{"Pandas":{"entries":[["Pandas Basics",["import pandas as pd\\nage = [1, 2, 3, 5, 6, 8, 8, 10, 9, 10, 11, 10, 11, 12, 15]\\nweight = [4, 4, 3, 3, 4, 3, 2, 2, 2, 1, 2, 1, 1, .5, .1]\\ndata = pd.DataFrame({\'age\': age, \'weight\': weight})\\ndata","[Pandas](https://pandas.pydata.org/) is a powerful library for managing large datasets and operating with them.\\n\\nHere, let\'s create a `DataFrame` for a hypothetical experiment about `age` vs. `weight`.\\n\\nThe columns have corresponding names, there is an index, and based on that many powerful transformation functions are available to ease working with such datasets."]],["Pandas DataFrame slicing",["from sklearn.datasets import load_iris\\nimport pandas as pd\\n\\ndata = load_iris()\\ndf = pd.DataFrame(data.data, columns=data.feature_names)\\ndf.head()","One of the most fundamental functions is to select only a part of the dataset.\\nThis example shows some ways how data can be sliced.\\n\\nTo save us some typing, we use the [Scikit Learn](http://scikit-learn.org) library to load the famous [iris dataset](https://en.wikipedia.org/wiki/Iris_flower_data_set)."]]],"sortweight":0},"Scikit Learn":{"entries":[["Introduction",["import numpy as np\\nimport matplotlib.pyplot as plt\\nfrom sklearn.cluster import KMeans\\nfrom sklearn.datasets import make_blobs\\n\\nX, y = make_blobs(n_samples=1000, centers = 4)\\ny_pred = KMeans(n_clusters=3).fit_predict(X)\\nplt.scatter(X[:, 0], X[:, 1], c=y_pred)","[Scikit Learn](http://scikit-learn.org) is an advanced machine learning library.\\n\\nIt\'s main design idea is to fit a prediction model to a dataset by an API, which is consistenly used throughout all methods.\\n\\nIn the first example here, we give the classical [K-Means](http://scikit-learn.org/stable/modules/clustering.html#k-means) algorithm a hard time:\\n4 random blobs but only 3 clusters to look for."]]],"sortweight":0},"Statistics":{"entries":[["Statsmodels: Ordinary Least Squares",["import numpy as np\\nimport pandas as pd\\nimport statsmodels.api as sm\\nimport statsmodels.formula.api as smf\\ndata = pd.DataFrame(\\n {\\n \'A\': [1, 2, 3, 5, 6, 8, 8.5, 10, 9, 10, 11, 10, 11, 12, 15],\\n \'B\': [4, 4, 3, 3, 4, 3, 2, 2, 2, 1, 2, 1, 1, .5, .1]\\n })\\nmodel = smf.ols(\'B ~ A + np.log(A) + 1\', data=data)\\nresults = model.fit()\\nprint(results.params)\\nprint()\\nprint(results.summary())","[Statsmodels](http://www.statsmodels.org) is a powerful library for classical statical modeling.\\n\\nThis example fits an ordinary least squares model for a given dataset.\\nIn the middle, the string `\'B ~ A + np.log(A) + 1\'` is an R-style formula for expressing the relationship."]]],"sortweight":0}},"Introduction":{"Files":{"entries":[["Reading and writing basics",["# Opening a file by name and specifying \'w\' for writing.\\nfile_writer = open(\'my-python-file.txt\', \'w\')\\n# \\\\n is used to insert a new line\\nfile_writer.write(\'This is some text!\\\\n\')\\nfile_writer.close()\\n# And we read it back. You can omit the second argument \'r\', that\'s the default.\\nfile_reader = open(\'my-python-file.txt\', \'r\')\\ncontent = file_reader.read()\\nprint(content)","Python has very good support to work with files.\\nLet\'s start with a simple example, where we write some text to a file and then read it back.\\n\\nOnce executed, look into the file explorer and look for a file named `made-by-python.txt`."]],["Reading CSV data",["open(\'example-data.csv\', \'w\').write(\'age,size\\\\n1,1.1\\\\n3,6.33\\\\n7,10\\\\n2,3\\\\n8,9\\\\n5,4\')\\n\\nimport csv\\nwith open(\'example-data.csv\') as csvfile:\\n for row in csv.reader(csvfile):\\n print(row)","Let\'s write some data to a csv file. Then, we read it using the [`csv` module](https://docs.python.org/3/library/csv.html).\\n\\nNote that each row is an array, but each entry is still a string. Use `float()` or `int()` to convert to numbers."]],["Reading CSV data via DictReader",["open(\'example-data.csv\', \'w\').write(\'age,size\\\\n1,1.1\\\\n3,6.33\\\\n7,10\\\\n2,3\\\\n8,9\\\\n5,4\')\\n\\nimport csv\\nwith open(\'example-data.csv\') as csvfile:\\n for row in csv.DictReader(csvfile):\\n print(row)","Similar to above, we use the `DictReader` to read in a dictionary.\\nThe first line (header) of the csv file will be used to name the entries in the dictionaries for each row."]],["UTF-8 special characters support",["# Python 3 only !\\nwith open(\\"utf8-encoding.txt\\", mode=\\"w\\", encoding=\\"utf8\\") as file_out:\\n file_out.write(\\"Spä¢ial ©ħa¶aĸŦ€r$\\\\n\\")","Most languages have special characters.\\nPython starting with version 3 has streamlined its use of [UTF-8](https://en.wikipedia.org/wiki/UTF-8) for all strings.\\nBelow is an example how you can make sure to use this standard for encoding text data."]],["UTF-8 in Python 2",["from codecs import open\\nwith open(\\"utf8-encoding2.txt\\", mode=\\"w\\", encoding=\\"utf8\\") as file_out:\\n file_out.write(u\\"Spä¢ial ©ħa¶aĸŦ€r$\\\\n\\")","In case you still work with Python 2, import the `open` function from the `codecs` library.\\n\\nNote the `u` in front of the string. That\'s used to signal a unicode string."]]],"sortweight":0},"Lists and Iterators":{"entries":[["Introduction List",["list = [1, 3, 2, 5, 1, 2]\\nfor i in list:\\n print(i)","Python does very well with operating on lists and iterating over them.\\nA \\"list\\" is a linearly ordered collection of objects, which can be processed in various ways."]],["Introduction Iterator",["def simple_iterator():\\n i = 0\\n while True:\\n i += (2*i) + 1\\n yield i\\n\\nfor i in simple_iterator():\\n print(i)\\n if i > 200:\\n break","Furthermore, an \\"iterator\\" is in some sense similar to a list, but it containing objects do not exist in memory.\\nAn exciting consequence of this is that there can be iterators which are effectively unbounded.\\n\\nLook careful at the following example: first a function is defined with an `yield` statement.\\nThis is like a `return` statement but it does not return – instead it waits until a value is consumed and continues running from there.\\n\\nAs a consequence, the second part produces a sequence of values until a breaking condition is met."]],["List comprehension",["[2*x + 1 for x in range(0, 10)]","Python has a special syntax to process lists.\\nIt is an expresion like this: `[statement(variable) for variable in (list or iterator)]"]],["Conditional list comprehension",["[x**2 for x in range(100) if (x % 27) == 0]","It is possible to append an if-conditional to select only some desired elements"]],["Conditional alternative list comprehension",["[x**2 if (x%3)==0 else x**3 for x in range(-10, 11)]","You can use an alternative-if in the form of `A if [statement is true] else B` as a statement, too."]],["Reversed list",["a = [1,2,3]\\n# use reversed to keep the original array the same\\nb = list(reversed(a))\\nprint(\\"a = \\", a)\\nprint(\\"b = \\", b)\\n# reverse an array in place\\na.reverse()\\nprint(\\"a = \\", a)","Use `reversed` to return a new reversed array, and use `.reverse()` to sort in place."]],["Sorted list",["a = [2,1,3]\\n# use sorted to keep the original array the same\\nb = list(sorted(a))\\nprint(\\"a = \\", a)\\nprint(\\"b = \\", b)\\n# use sort to sort an array in place\\na.sort()\\nprint(\\"a = \\", a)","Use `sorted` to return a new sorted array, and use `.sort()` to sort in place."]]],"sortweight":0},"Tutorial":{"entries":[["Hello World",["print(\\"Hello World\\")","The \\"Hello World\\" program"]],["Objects/Instances",["\\"hello\\" # creates an object of type \\"string\\" with the value \\"hello\\"\\n5.5 # the floating point number 5.5","One of the most fundamental building blocks of a Python program are \\"Objects\\".\\nThey are concrete \\"instances\\" of a certain type.\\nAs a real-world analogue, you can think of a pair of shoes as a type,\\nand the specific example of shoes you are wearing right now as an instance of that type.\\nYour specific shoes also have certain properties, like a specific size, a color, a make, maybe even a serial number, etc.\\nThe type \\"shoe\\" would only describe these properties, while a specific pair has concrete values.\\nMore about this at a later point."]],["Variables",["x = 1\\ny = x + 1\\nprint(x)\\nprint(y)","A variable is a name for an object.\\nIt is done via this syntax:\\n\\n```\\nvariablename = object\\n```\\n\\n`print` is a function to show the object as a string."]],["Print Data",["x = \\"Hello\\"\\ny = 2.123456789\\nprint(\\"%s World, y = %f\\" % (x, y))\\nprint(\\"x={x}, y={y:.3f}\\".format(**locals()))","The \\"Hello World\\" program printing some values."]],["Expressions",["print((5 + 6) * 11)\\nz = 3 # assign a variable, then use it in an expression\\nprint((1 + z)**2)\\nfrom math import sqrt\\nprint(sqrt(z))","Expressions are constructued by combining several object.\\nUsually, they can be evaluated, because operators and functions are used to build the expression.\\n\\nFurthermore, use parenthesis to control the order of the evaluation!"]],["Functions",["def function1(x, y):\\n z = 10 * x + y\\n return z\\n\\nprint(function1(4, 5))\\nprint(function1(1,-1))","A function call is one of the most basic levels of abstraction. A common subroutine of evaluations is run with varying initial arguments. The `return` statement is very important: data flows back to where the functions has been called."]],["Functions (nested)",["def foo(x):\\n return 2*x+1\\nprint(foo(1 + foo(3)) - 2)","It is fine to nest functions in more complex expressions."]],["Data Structure: List",["x = [42, \\"Hello\\", [1,2,3]]\\nprint(x)\\nx.append(\\"World\\")\\nprint(x)","To organize information in a program, data structures are here to help. A very basic one is an ordered collection of arbitrary objects. Such a `list` object is constructed by listing objects between `[ ... ]` delimited by a commas `,`."]],["List access",["l = [4, 5, -1, 2]\\nprint(l[1])\\nprint(l[-1])\\nprint(l[0] + 2 * l[1])","To access elements at a specific location, use `[]` brackets with the index number.\\nCounting starts at zero and negative values index in the other direction from the end.\\n\\nAlso be aware, that like with functions lists might also be nested."]],["Control Structure: if/else",["x = -8\\nprint(\'x is %s\' % x)\\nif x > 0: # note the colon!\\n print(\'x is positive\')\\nelse:\\n print(\'x is not positive\')\\nprint(\'this line is always executed!\')\\n\\n# TODO: change the -8 to a positive value and see how the flow changes","Code is executed line by line, but it can be directed to flow in more complex ways.\\nAn `if` decides if a block of code is executed, or – together with `else` – decides between two blocks.\\n\\nIn Python, blocks are indented by spaces (usually two or four) from the beginning for the line.\\nNested blocks are indented multiple times (4 or 8 times, etc.)."]],["Control Structure: for",["for i in [\'a\', \'c\', \'abc\', \'x\']:\\n print(\\"variable i is %s\\" % i)\\nfor j in range(3):\\n for k in range(5):\\n print(\\"j: {} + k: {} = {}\\".format(j, k, j+k))","A `for`-loop repeates a block of code by consecutively assigning a local variable with values from a list or iterator."]],["Data Structure: Dict(ionary)",["d = dict()\\nd[42] = \\"The Answer\\"\\nd[\\"what\\"] = [\\"this\\", \\"and\\", \\"that\\"]\\nd[(4, 2)] = 99\\nprint(d[42])\\nprint(d[(4,2)])\\nprint(d.keys())\\nprint(42 in d)","A dictionary is an mapping of (immutable) objects to arbitrary objects.\\nThe immutable objects are called \\"keys\\" and are most commonly numbers, strings or tuples.\\n\\nTo set a key in a dictionary, assign it like this: `var[\\"x\\"] = 42`.\\n\\nLater, accessing a dictionary is similar to a list:\\n`var[\\"x\\"]` retrieves the entry with the name `\\"x\\"` from the dictionary referenced by the variable `var`.\\nAs by the assignment above, the retrived object is the number `42`."]],["Classes",["class Shoe(object):\\n def __init__(self, size, color):\\n self.size = size\\n self.color = color\\n def double(self):\\n \\"\\"\\"return twice the size of the shoe\\"\\"\\"\\n return 2 * self.size\\n\\n# instantiation:\\ns1 = Shoe(40, \\"green\\")\\ns2 = Shoe(43, \\"black\\")\\nprint(s1.color)\\nprint(s2.double())\\nprint(type(s2)) # the type of the object referenced by s1 is \\"Shoe\\"","A `class` is the usual way how someone can define a custom `type`.\\nWe define a class `Shoe` with a specific color and size.\\nUnder the hood, a class is like a dictionary but with some extras and an enhanced syntax.\\nAdditionally, \\"methods\\" are functions in a class.\\nThey are used to compute a derived value from the data of an instantiated object.\\nThe method `__init__` is special: it is called upon instantiation and used to set the values of the object."]]],"sortweight":0}},"NumPy":{"Creating arrays":{"entries":[["New array of given shape",["new_array = np.zeros((4,3,), dtype=complex)","New array of given shape"]],["New array shaped like another",["new_array = np.zeros_like(old_array, dtype=complex)","New array shaped like another"]],["Copy of existing data",["new_array = np.copy(old_array)","Copy of existing data"]],["Array from list of data",["new_array = np.array([1.2, 3.4, 5.6])","Array from list of data"]],["Evenly spaced values within a given interval",["new_array = np.arange(1, 10, 2)","Evenly spaced values within a given interval"]],["Evenly spaced numbers over a specified interval",["new_array = np.linspace(1., 10., num=120, endpoint=True)","Evenly spaced numbers over a specified interval"]],["Numbers spaced evenly on a log scale",["new_array = np.logspace(1., 10., num=120, endpoint=True, base=2)","Numbers spaced evenly on a log scale"]],["Coordinate matrices from coordinate vectors",["x = np.linspace(0, 1, 7)\\ny = np.linspace(0, 1, 11)\\nxx, yy = np.meshgrid(x, y)\\nxx, yy","Coordinate matrices from coordinate vectors"]],["Return views of the data, split into $N$ groups",["x = np.arange(12)\\na,b,c = np.split(x, 3)\\na, b, c","Return views of the data, split into $N$ groups"]],["Return views of the data, split at given indices along given axis",["x = np.arange(27).reshape((3,9))\\na,b,c = np.split(x, [2,6], axis=1)\\na, b, c","Return views of the data, split at given indices along given axis"]],["Return copy of arrays, combined into one",["a = np.arange(30).reshape((2,3,5))\\nb = np.arange(42).reshape((2,3,7))\\nnp.concatenate((a, b), axis=2)","Return copy of arrays, combined into one"]]],"setup":"import numpy as np","sortweight":0,"variables":{"a":"np.array([3, 4, -1, 9.81])","a_max":"np.array([1, 1, 5, 10])","a_min":"np.array([-1, -1, 0, 0])","axis1":0,"axis2":1,"b":"np.array([0, -1, 2, -3])","n":2,"old_array":"np.array([3, 4, -1, 9.81])","x":"np.array([ 0, 1, 4.4, -9])","x1":"np.array([0.1, 1, 2.2, 3.5])","x2":"np.array([ -4, 3, 0.2, 1.5])"}},"File I/O":{"entries":[["Read data from simple text file",["data = np.loadtxt(filename)","Read data from simple text file"]],["Read data from text file with missing values",["data = np.genfromtxt(filename)","Read data from text file with missing values"]],["Read data from .npy or .npz file",["data = np.load(filename)","Read data from .npy or .npz file"]],["Write single array to text file",["np.savetxt(filename, x)","Write single array to text file"]],["Write multiple arrays to text file",["np.savetxt(filename, np.transpose((x, y, z)))","Write multiple arrays to text file"]],["Write single array to single .npy file",["np.save(filename, x)","Write single array to single .npy file"]],["Write multiple arrays to single .npy file",["np.save(filename, np.transpose((x, y, z)))","Write multiple arrays to single .npy file"]],["Write multiple arrays to single .npz file",["np.savez(filename, x, y, z)","Write multiple arrays to single .npz file"]],["Write multiple arrays to single compressed .npz file",["np.savez_compressed(filename, x, y, z)","Write multiple arrays to single compressed .npz file"]]],"setup":"import numpy as np","sortweight":0,"variables":{"a":"np.array([3, 4, -1, 9.81])","a_max":"np.array([1, 1, 5, 10])","a_min":"np.array([-1, -1, 0, 0])","axis1":0,"axis2":1,"b":"np.array([0, -1, 2, -3])","n":2,"old_array":"np.array([3, 4, -1, 9.81])","x":"np.array([ 0, 1, 4.4, -9])","x1":"np.array([0.1, 1, 2.2, 3.5])","x2":"np.array([ -4, 3, 0.2, 1.5])"}},"Indexing":{"entries":[["Test if array is empty",["if a.size > 0: # Never use `if a` or `if len(a)` for numpy arrays\\n print(a)","Test if array is empty"]],["Get number of dimensions of array",["a.ndim","Get number of dimensions of array"]],["Get shape of array",["a.shape","Get shape of array"]]],"setup":"import numpy as np","sortweight":0,"variables":{"a":"np.array([3, 4, -1, 9.81])","a_max":"np.array([1, 1, 5, 10])","a_min":"np.array([-1, -1, 0, 0])","axis1":0,"axis2":1,"b":"np.array([0, -1, 2, -3])","n":2,"old_array":"np.array([3, 4, -1, 9.81])","x":"np.array([ 0, 1, 4.4, -9])","x1":"np.array([0.1, 1, 2.2, 3.5])","x2":"np.array([ -4, 3, 0.2, 1.5])"}},"Indexing / Index a multi-dimensional array":{"entries":[["Get one element",["a = np.arange(30).reshape((2,3,5))\\na[1, 2, 4]","Get one element"]],["Get first $N$ elements along each final axis",["a = np.arange(30).reshape((2,3,5))\\na[:, :, :4]","Get first $N$ elements along each final axis"]],["Get last $N$ elements along each final axis",["a = np.arange(30).reshape((2,3,5))\\na[:, :, -3:]","Get last $N$ elements along each final axis"]],["Get elements $N$ to $M$ along each final axis",["a = np.arange(30).reshape((2,3,5))\\na[:, :, 3:5]","Get elements $N$ to $M$ along each final axis"]],["Get elements satisfying a condition (flattened result)",["a = np.arange(30).reshape((2,3,5))\\na[a>5]","Get elements satisfying a condition (flattened result)"]]],"setup":"import numpy as np","sortweight":0,"variables":{"a":"np.array([3, 4, -1, 9.81])","a_max":"np.array([1, 1, 5, 10])","a_min":"np.array([-1, -1, 0, 0])","axis1":0,"axis2":1,"b":"np.array([0, -1, 2, -3])","n":2,"old_array":"np.array([3, 4, -1, 9.81])","x":"np.array([ 0, 1, 4.4, -9])","x1":"np.array([0.1, 1, 2.2, 3.5])","x2":"np.array([ -4, 3, 0.2, 1.5])"}},"Indexing / Index a one-dimensional array":{"entries":[["Get one element",["a = np.arange(10)\\na[3]","Get one element"]],["Get first $N$ elements",["a = np.arange(10)\\na[:3]","Get first $N$ elements"]],["Get last $N$ elements",["a = np.arange(10)\\na[-3:]","Get last $N$ elements"]],["Get elements $N$ to $M$",["a = np.arange(10)\\na[3:6]","Get elements $N$ to $M$"]],["Get elements satisfying a condition",["a = np.arange(10)\\na[a>5]","Get elements satisfying a condition"]]],"setup":"import numpy as np","sortweight":0,"variables":{"a":"np.array([3, 4, -1, 9.81])","a_max":"np.array([1, 1, 5, 10])","a_min":"np.array([-1, -1, 0, 0])","axis1":0,"axis2":1,"b":"np.array([0, -1, 2, -3])","n":2,"old_array":"np.array([3, 4, -1, 9.81])","x":"np.array([ 0, 1, 4.4, -9])","x1":"np.array([0.1, 1, 2.2, 3.5])","x2":"np.array([ -4, 3, 0.2, 1.5])"}},"Indexing / Index an array of unknown dimension":{"entries":[["Get first $N$ elements along each final axis",["a = np.arange(30).reshape((2,3,5))\\na[..., :4]","Get first $N$ elements along each final axis"]],["Get last $N$ elements along each final axis",["a = np.arange(30).reshape((2,3,5))\\na[..., -3:]","Get last $N$ elements along each final axis"]],["Get elements $N$ to $M$ along each final axis",["a = np.arange(30).reshape((2,3,5))\\na[..., 3:5]","Get elements $N$ to $M$ along each final axis"]],["Get elements satisfying a condition (flattened result)",["a = np.arange(30).reshape((2,3,5))\\na[a>5]","Get elements satisfying a condition (flattened result)"]]],"setup":"import numpy as np","sortweight":0,"variables":{"a":"np.array([3, 4, -1, 9.81])","a_max":"np.array([1, 1, 5, 10])","a_min":"np.array([-1, -1, 0, 0])","axis1":0,"axis2":1,"b":"np.array([0, -1, 2, -3])","n":2,"old_array":"np.array([3, 4, -1, 9.81])","x":"np.array([ 0, 1, 4.4, -9])","x1":"np.array([0.1, 1, 2.2, 3.5])","x2":"np.array([ -4, 3, 0.2, 1.5])"}},"Polynomials":{"entries":[["Setup",["import numpy as np\\nfrom numpy.polynomial import Polynomial as P\\nfrom numpy.polynomial import Chebyshev as T\\nfrom numpy.polynomial import Legendre as Le\\nfrom numpy.polynomial import Laguerre as La\\nfrom numpy.polynomial import Hermite as H\\nfrom numpy.polynomial import HermiteE as HE","Setup"]],["Instantiate from coefficients",["poly = P([1, 2, 3])","Instantiate from coefficients"]],["Instantiate from roots",["poly = P.fromroots([1, 2, 3])","Instantiate from roots"]],["Instantiate from basis element $n$",["poly = P.basis(n)","Instantiate from basis element $n$"]],["Convert between types",["from numpy.polynomial import Chebyshev\\npolyT = poly.convert(kind=Chebyshev)","Convert between types"]],["Get coefficients (constant at index 0, higher indices for higher orders)",["poly.coef","Get coefficients (constant at index 0, higher indices