mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 14:01:15 +00:00
refined numpy syntax
This commit is contained in:
parent
a76fa9a01b
commit
6cb30cfb38
1
tutorials/.~lock.matrix_cheatsheet_only.html#
Normal file
1
tutorials/.~lock.matrix_cheatsheet_only.html#
Normal file
|
@ -0,0 +1 @@
|
|||
,sebastian,Macintosh.local,16.06.2014 22:50,file:///Users/sebastian/Library/Application%20Support/LibreOffice/4;
|
|
@ -5,7 +5,7 @@
|
|||
<title></title>
|
||||
<meta name="generator" content="LibreOffice 4.2.4.2 (MacOSX)">
|
||||
<meta name="created" content="0;0">
|
||||
<meta name="changed" content="20140605;223752655486000">
|
||||
<meta name="changed" content="20140616;225009144635000">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
td p { color: #000000; font-family: "Verdana"; font-size: 12pt }
|
||||
|
@ -22,7 +22,7 @@
|
|||
<col width="511">
|
||||
<col width="690">
|
||||
<tr>
|
||||
<td height="57" bgcolor="#0066cc" style="border: none; padding: 0in">
|
||||
<td height="58" bgcolor="#0066cc" style="border: none; padding: 0in">
|
||||
<p align="center"><font color="#ffffff"><font face="Arial"><font size="5" style="font-size: 18pt"><b>Task</b></font></font></font></p>
|
||||
</td>
|
||||
<td bgcolor="#0066cc" style="border: none; padding: 0in">
|
||||
|
@ -92,10 +92,15 @@
|
|||
3</font></font></p>
|
||||
</td>
|
||||
<td bgcolor="#cfe7f5" style="border-top: none; border-bottom: none; border-left: 1px dotted #000000; border-right: 1px dotted #000000; padding: 0in 0.02in">
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
a = np.array([[1],[2],[3]])<br><br><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
a<br>array([[1],<br> [2],<br>
|
||||
[3]])</font></font></p>
|
||||
<p align="left"><font color="#ff420e"><font face="Andale Mono"><font size="2" style="font-size: 10pt"><b>P></b></font></font></font><font face="Andale Mono"><font size="1" style="font-size: 8pt">
|
||||
</font></font><font face="Andale Mono"><font size="1" style="font-size: 8pt">a</font></font><font color="#2fff12"><font face="AndaleMono, serif"><font size="4" style="font-size: 14pt">
|
||||
</font></font></font><font color="#000000"><font face="Andale Mono"><font size="1" style="font-size: 8pt">=
|
||||
np.array([1,2,3]).reshape(1,3)</font></font></font></p>
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><br></font></font><font color="#ff420e"><font face="Andale Mono"><font size="2" style="font-size: 10pt"><b>P></b></font></font></font><font face="Andale Mono"><font size="1" style="font-size: 8pt">
|
||||
</font></font><font color="#000000"><font face="Andale Mono"><font size="1" style="font-size: 8pt">b.shape<br>(1,
|
||||
3)</font></font></font></p>
|
||||
<p align="left"><br>
|
||||
</p>
|
||||
</td>
|
||||
<td bgcolor="#cfe7f5" style="border-top: none; border-bottom: none; border-left: 1px dotted #000000; border-right: 1px dotted #000000; padding: 0in 0.02in">
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><font color="#0000ff"><font size="2" style="font-size: 10pt"><b>R></b></font></font>
|
||||
|
@ -124,6 +129,14 @@
|
|||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
b = np.array([1,2,3])<br><br><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
b<br>array([1, 2, 3])</font></font></p>
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt">#
|
||||
note that numpy doesn't have <br># explicit “row-vectors”, but
|
||||
1-D <br># arrays</font></font></p>
|
||||
<p style="margin-bottom: 0in"><font face="Liberation Serif, serif"><font size="3" style="font-size: 12pt"><font color="#ff420e"><font face="Andale Mono"><font size="2" style="font-size: 10pt"><b>P></b></font></font></font><font color="#2fff12"><font face="AndaleMono, serif"><font size="1" style="font-size: 8pt"><b>
|
||||
</b></font></font></font><font color="#000000"><font face="Andale Mono"><font size="1" style="font-size: 8pt">b.shape</font></font></font></font></font></p>
|
||||
<p style="margin-bottom: 0in"><font face="Andale Mono"><font size="1" style="font-size: 8pt">(3,)</font></font></p>
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><br></font></font><br>
|
||||
</p>
|
||||
</td>
|
||||
<td bgcolor="#ffffff" style="border-top: none; border-bottom: none; border-left: 1px dotted #000000; border-right: 1px dotted #000000; padding: 0in 0.02in">
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><font color="#0000ff"><font size="2" style="font-size: 10pt"><b>R></b></font></font>
|
||||
|
@ -213,7 +226,7 @@
|
|||
</td>
|
||||
<td bgcolor="#cfe7f5" style="border-top: none; border-bottom: none; border-left: 1px dotted #000000; border-right: 1px dotted #000000; padding: 0in 0.02in">
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
np.ones([3,2])<br>array([[ 1., 1.],<br>
|
||||
np.ones((3,2))<br>array([[ 1., 1.],<br>
|
||||
[ 1., 1.],<br> [ 1., 1.]])</font></font></p>
|
||||
</td>
|
||||
<td bgcolor="#cfe7f5" style="border-top: none; border-bottom: none; border-left: 1px dotted #000000; border-right: 1px dotted #000000; padding: 0in 0.02in">
|
||||
|
@ -551,10 +564,10 @@
|
|||
A = np.array([[1,2,3],[4,5,6],[7,8,9]])<br><br><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
A<br>array([[1, 2, 3],<br> [4, 5, 9],<br>
|
||||
[7, 8, 9]])<br><br><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
total_elements = A.shape[0] * A.shape[1]<br><br><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
B = A.reshape(1, total_elements) <br><br># or
|
||||
A.reshape(1,9)<br># Alternative: A.shape = (1,9) <br>#
|
||||
to change the array in place<br><br><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
total_elements = np.prod(A.shape)</font></font></p>
|
||||
<p align="left"><font face="Andale Mono"><font size="1" style="font-size: 8pt"><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
B = A.reshape(1, total_elements) <br><br># alternative
|
||||
shortcut:<br># A.reshape(1,-1)<br><br><font color="#ff420e"><font size="2" style="font-size: 10pt"><b>P></b></font></font>
|
||||
B<br>array([[1, 2, 3, 4, 5, 6, 7, 8, 9]])</font></font></p>
|
||||
</td>
|
||||
<td bgcolor="#ffffff" style="border-top: none; border-bottom: none; border-left: 1px dotted #000000; border-right: 1px dotted #000000; padding: 0in 0.02in">
|
||||
|
@ -1107,7 +1120,7 @@
|
|||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td height="539" bgcolor="#ffffff" style="border-top: none; border-bottom: none; border-left: none; border-right: 1px solid #000000; padding-top: 0in; padding-bottom: 0in; padding-left: 0in; padding-right: 0.02in">
|
||||
<td height="540" bgcolor="#ffffff" style="border-top: none; border-bottom: none; border-left: none; border-right: 1px solid #000000; padding-top: 0in; padding-bottom: 0in; padding-left: 0in; padding-right: 0.02in">
|
||||
<p align="left"><font face="Arial"><font size="2" style="font-size: 10pt"><b>Generating
|
||||
a Gaussian dataset:<br><br>creating random vectors from the
|
||||
multivariate normal<br>distribution given mean and covariance
|
||||
|
|
Loading…
Reference in New Issue
Block a user