Unverified Commit 44ec750f authored by Guillaume Anciaux's avatar Guillaume Anciaux
Browse files

adding lecture of the day

parent f98a45ed
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<title>talk slides</title>
<!-- Loading the init_reveal macro -->
<!-- Load and configure reveal -->
<script src="js-markdown-extra.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<!-- General and theme style sheets -->
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<link rel="stylesheet" href="reveal.js/css/theme/simple.css" id="theme">
<!-- Loading the mathjax macro -->
<!-- Load mathjax -->
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true
},
// Center justify equations in code and markdown cells. Elsewhere
// we use CSS to left justify single line equations in code cells.
displayAlign: 'center',
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}},
linebreaks: { automatic: true }
}
});
</script>
<!-- End of mathjax configuration -->
<!-- Get Font-awesome from cdn -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css">
<!-- End of reveal parts -->
<style type="text/css">
.reveal {
font-size: 16px;
}
.reveal h1 {
font-size: 200%;
}
.reveal h2 {
font-size: 150%;
}
.text_cell_render {
text-align: left;
}
a.anchor-link:link {
text-decoration: none;
visibility: hidden;
}
.slide {
}
div.slide{
border-style: solid;
border-width: 2px;
/* display: flex;*/
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
margin-top: 5px;
margin-bottom: 5px;
padding-left: 100px;
padding-right: 100px;
padding-top: 2px;
padding-bottom: 2px;
width: 1000px;
}
/*******************************
** highing tpart
*******************************/
.highlight_text {
color: blue;
}
.highlight-base {
color: #000;
}
.highlight-variable {
color: #000;
}
.highlight-variable-2 {
color: #1a1a1a;
}
.highlight-variable-3 {
color: #333333;
}
.highlight-string {
color: #BA2121;
}
.highlight-comment {
color: #408080;
font-style: italic;
}
.highlight-number {
color: #080;
}
.highlight-atom {
color: #88F;
}
.highlight-keyword {
color: #008000;
font-weight: bold;
}
.highlight-builtin {
color: #008000;
}
.highlight-error {
color: #f00;
}
.highlight-operator {
color: #AA22FF;
font-weight: bold;
}
.highlight-meta {
color: #AA22FF;
}
.highlight-def {
color: #00f;
}
.highlight-string-2 {
color: #f50;
}
.highlight-qualifier {
color: #555;
}
.highlight-bracket {
color: #997;
}
.highlight-tag {
color: #170;
}
.highlight-attribute {
color: #00c;
}
.highlight-header {
color: blue;
}
.highlight-quote {
color: #090;
}
.highlight-link {
color: #00c;
}
.highlight .hll { background-color: #ffffcc }
//.highlight { background: #f8f8f8; }
.highlight .c { color: #408080; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .ch { color: #408080; font-style: italic } /* Comment.Hashbang */
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
.highlight .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0044DD } /* Generic.Traceback */
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #B00040 } /* Keyword.Type */
.highlight .m { color: #666666 } /* Literal.Number */
.highlight .s { color: #BA2121 } /* Literal.String */
.highlight .na { color: #7D9029 } /* Name.Attribute */
.highlight .nb { color: #008000 } /* Name.Builtin */
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.highlight .no { color: #880000 } /* Name.Constant */
.highlight .nd { color: #AA22FF } /* Name.Decorator */
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0000FF } /* Name.Function */
.highlight .nl { color: #A0A000 } /* Name.Label */
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #19177C } /* Name.Variable */
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #666666 } /* Literal.Number.Bin */
.highlight .mf { color: #666666 } /* Literal.Number.Float */
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
.highlight .sa { color: #BA2121 } /* Literal.String.Affix */
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
.highlight .dl { color: #BA2121 } /* Literal.String.Delimiter */
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.highlight .sx { color: #008000 } /* Literal.String.Other */
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0000FF } /* Name.Function.Magic */
.highlight .vc { color: #19177C } /* Name.Variable.Class */
.highlight .vg { color: #19177C } /* Name.Variable.Global */
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
.highlight .vm { color: #19177C } /* Name.Variable.Magic */
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="--git-pull-upstream-master--"><center> <span style="color:red"> git pull upstream master </span> </center><a class="anchor-link" href="#--git-pull-upstream-master--">&#182;</a></h1>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h1><center> Answer questions from <br> the previous session</center></h1>
</div>
</div><div class="full" style="width: 100%; float: left">
<div class="cell border-box-sizing code_cell rendered">
</div>
</div></div>
</section></section><section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Python-complements-"><center>Python complements </center><a class="anchor-link" href="#Python-complements-">&#182;</a></h1>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Default-parameters-of-functions">Default parameters of functions<a class="anchor-link" href="#Default-parameters-of-functions">&#182;</a></h2><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="k">return</span> <span class="n">a</span><span class="o">+</span><span class="n">b</span>
</pre></div>
</div>
</div><div class="fragment" style="width: 100%;float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="args-and-kwargs"><em>args</em> and <em>kwargs</em><a class="anchor-link" href="#args-and-kwargs">&#182;</a></h2><ul>
<li><strong>args</strong>: list containing un-named arguments</li>
<li><strong>kwargs</strong>: dictionary containing the named arguments</li>
</ul>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;args:&#39;</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;kwrags:&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
<span class="k">return</span> <span class="n">a</span><span class="o">+</span><span class="mi">1</span>
<span class="n">foo</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">toto</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">tata</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
</div></div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="lambda-functions:-for_each">lambda functions: for_each<a class="anchor-link" href="#lambda-functions:-for_each">&#182;</a></h2><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="mi">10</span><span class="p">)</span>
<span class="n">l</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">for_each</span><span class="p">(</span><span class="n">_list</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">_list</span><span class="p">:</span>
<span class="n">func</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="n">for_each</span><span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="n">foo</span><span class="p">)</span>
<span class="n">for_each</span><span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="mi">10</span><span class="p">))</span>
</pre></div>
</div>
</div><div class="fragment" style="width: 100%;float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="lambda-functions:-transform">lambda functions: transform<a class="anchor-link" href="#lambda-functions:-transform">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">applied</span> <span class="o">=</span> <span class="p">[</span><span class="n">foo</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">l</span><span class="p">]</span>
<span class="n">applied</span> <span class="o">=</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">*</span><span class="mi">10</span><span class="p">)(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">l</span><span class="p">]</span>
</pre></div>
</div>
</div></div></div>
</section></section><section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="-Numpy-"><center> Numpy </center><a class="anchor-link" href="#-Numpy-">&#182;</a></h1><p><a href="http://docs.scipy.org/doc/numpy/reference/">Numpy reference</a></p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
</pre></div>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Creating-multi-dimentional-array-zero-filled">Creating multi-dimentional array zero-filled<a class="anchor-link" href="#Creating-multi-dimentional-array-zero-filled">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
</pre></div>
</div>
</div><div class="fragment" style="width: 100%;float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Creating--multi-dimentional-array-from-list/tuple">Creating multi-dimentional array from list/tuple<a class="anchor-link" href="#Creating--multi-dimentional-array-from-list/tuple">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],[</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">],[</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">]]</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
<span class="n">t</span> <span class="o">=</span> <span class="p">((</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),(</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">),(</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">))</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
</pre></div>
</div>
</div></div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Creating-special-matrix">Creating special matrix<a class="anchor-link" href="#Creating-special-matrix">&#182;</a></h2><div class="highlight"><pre><span></span><span class="c1"># Identity matrix</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="c1"># Matrix filled with ones</span>
<span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
<span class="c1"># diagonal matrix</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span>
<span class="c1"># random matrix</span>
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Numpy-Slicing"><a href="https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html">Numpy Slicing</a><a class="anchor-link" href="#Numpy-Slicing">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
</pre></div>
<ul>
<li>Slicing syntax: m[start:end:stride]</li>
</ul>
</div>
</div><div class="fragment" style="width: 100%;float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<div class="highlight"><pre><span></span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># access index 2</span>
<span class="n">m</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="c1"># access last index</span>
<span class="n">m</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># sub vector m[0],m[1]</span>
<span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="c1"># access m[1], m[2], m[3]</span>
<span class="n">m</span><span class="p">[::</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># access even indexes</span>
<span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">::</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># access odd indexes</span>
<span class="n">m</span><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">,:]</span> <span class="c1"># access in decreasing order</span>
</pre></div>
</div>
</div></div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Component-based-algebra">Component-based algebra<a class="anchor-link" href="#Component-based-algebra">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
<span class="c1">#component by component operation</span>
<span class="n">n</span> <span class="o">=</span> <span class="n">m</span><span class="o">*</span><span class="mi">2</span>
<span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="o">+</span><span class="n">n</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="o">*</span><span class="n">n</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<span class="nb">print</span><span class="p">((</span><span class="n">m</span><span class="o">-</span><span class="n">n</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="np.array.shape"><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.shape.html">np.array.shape</a><a class="anchor-link" href="#np.array.shape">&#182;</a></h2><ul>
<li>Size/Dimension of a vector/matrix/tensor is its <strong>shape</strong></li>
<li>It is a tuple</li>
</ul>
<div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">shape</span><span class="p">))</span>
</pre></div>
</div>
</div><div class="full" style="width: 100%; float: left">
<div class="cell border-box-sizing code_cell rendered">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>[[0.3378656 0.0313648 0.09493196]
[0.28114122 0.57254829 0.88136671]]
(2, 3) &lt;class &#39;tuple&#39;&gt;
</pre>
</div>
</div>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="flatten"><a href="https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.ndarray.flatten.html">flatten</a><a class="anchor-link" href="#flatten">&#182;</a></h2><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
<span class="n">flat</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">flat</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="n">flat</span><span class="p">)</span>
</pre></div>
</div>
</div><div class="full" style="width: 100%; float: left">
<div class="cell border-box-sizing code_cell rendered">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>[[0.3378656 0.0313648 0.09493196]
[0.28114122 0.57254829 0.88136671]]
(6,) [0.3378656 0.0313648 0.09493196 0.28114122 0.57254829 0.88136671]
</pre>
</div>
</div>
</div>
</div><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="reshape"><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html#numpy.reshape">reshape</a><a class="anchor-link" href="#reshape">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">reshaped</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">reshaped</span><span class="p">)</span>
</pre></div>
</div>
</div><div class="full" style="width: 100%; float: left">
<div class="cell border-box-sizing code_cell rendered">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>[[0.3378656 0.0313648 ]
[0.09493196 0.28114122]
[0.57254829 0.88136671]]
</pre>
</div>
</div>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Scipy-linear-algebra-routines"><a href="http://docs.scipy.org/doc/numpy/reference/routines.linalg.html">Scipy linear algebra routines</a><a class="anchor-link" href="#Scipy-linear-algebra-routines">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],[</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">],[</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">]])</span>
<span class="n">n</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]])</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="c1"># transposition</span>
<span class="n">m2</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">T</span>
<span class="c1"># matrix-matrix operation</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">)</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">m</span><span class="nd">@n</span>
<span class="c1"># matrix-vector operation</span>
<span class="n">v2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">v</span><span class="p">)</span>
<span class="n">v2</span> <span class="o">=</span> <span class="n">m</span><span class="nd">@v</span>
<span class="c1">#matrix inversion</span>
<span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
</pre></div>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Numpy-summations"><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html">Numpy summations</a><a class="anchor-link" href="#Numpy-summations">&#182;</a></h2><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],[</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">],[</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">]])</span>
</pre></div>
<ul>
<li><p>$\sum_{i,j} m_{ij}$</p>
<div class="highlight"><pre><span></span><span class="n">m</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span>
</pre></div>
</li>
<li><p>$\sum_{i} m_{ij}$ and $\sum_{j} m_{ij}$</p>
</li>
</ul>
<div class="highlight"><pre><span></span><span class="n">m</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">m</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
<ul>
<li>norm: $\sqrt{\sum_{ij} m_{ij}^2}$</li>
</ul>
<div class="highlight"><pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">((</span><span class="n">m</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">())</span>
</pre></div>
</div>
</div></div>
</section><section>
<div class="slide" style="float: left"><div class="full" style="width: 100%; float: left">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Einsum"><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html">Einsum</a><a class="anchor-link" href="#Einsum">&#182;</a></h2><ul>
<li>Tensor product with einstein notation</li>
<li>mat-vec product: $u_i = m_{ik} v_k$</li>
</ul>
<div class="highlight"><pre><span></span><span class="n">u</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">einsum</span><span class="p">(</span><span class="s1">&#39;ik,k-&gt;i&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
</pre></div>
<ul>
<li>dot product: $norm = v_k v_k$</li>
</ul>
<div class="highlight"><pre><span></span><span class="n">norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">einsum</span><span class="p">(</span><span class="s1">&#39;k,k-&gt;&#39;</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
</pre></div>
<ul>
<li>Transposition</li>
</ul>
<div class="highlight"><pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">einsum</span><span class="p">(</span><span class="s1">&#39;ij-&gt;ji&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
</pre></div>
</div>
</div></div>
</section><section>