Professional Documents
Culture Documents
.
Python: Interactive computing with bpython and IPython
.
.. .
.
Netsoc
Stephen Shaw
2010
Schedule
This week - The bpython interpreter, the IPython interpreter, scipy,
numpy, sympy, pylab
These slides: http://www.netsoc.tcd.ie/tutorials/2011/02/08/
python-tutorial-3/
As we've seen, the REPL is great for playing around with python quickly
Standard REPL is quite minimal
Gets a bit tedious after a while
We can do a lot better
Dynamic objects :
In [1]: ! uptime
15:10:29 up 143 days , 23:12 , 128 users , load �
average : 1.44 , 1.24 , 1.08
In [1]: ! zsh
stesh@cube : ˜ [21:14]% echo $ SHELL
/ usr / bin / zsh
In [2]: dirs = ! ls /
In [2]: % hist
1:
f o r i i n range (99 ,0 , -1) :
p r i n t '% d bottles of beer on the wall ' % i
Can now run this entire block of code by just typing bottles
Macros can have arguments too
store them in a global list called _margv
In [4]: A
Out [4]:
matrix ([[1 , 2 , 3] ,
[4 , 5 , 5] ,
[6 , 6 , 8]])
In [5]: A . T
Out [5]:
matrix ([[1 , 4 , 6] ,
[2 , 5 , 6] ,
[3 , 5 , 8]])
In [7]: A * B
Out [7]:
matrix ([[ 29 , 29 , 32] ,
[ 61 , 75 , 78] ,
[ 92 , 100 , 112]])
In [3]: y = x **2 + 4* x - 12
In [4]: solve (y , x )
Out [4]: [2 , -6]
In [5]: diff (y , x )
Out [5]: 4 + 2* x
In [6]: integrate (y , x )
Out [6]: -12* x + 2* x **2 + (1/3) * x **3
1 Can only tell you if two graphs definitely aren't isomorphic - determining if they definitely
In [2]: G = nx . Graph ()
In [4]: G . add_edges_from ([(1 ,4) ,(6 ,7) ,(6 ,8) ,(3 ,4) ,(3 ,7) ,(1 ,8) ,(1 ,7) ])
In [5]: G . number_of_nodes ()
Out [5]: 8
In [6]: G [1]
Out [6]: {4: {} , 7: {} , 8: {}}
You can view plots on screen, or write them to any of several formats
Can customize colors, thickness, fonts, etc.