CoCalc Public Filesanaconda.ipynbOpen with one click!
Authors: Testing CoCalc, Harald Schilly, ℏal Snyder, William A. Stein
Views : 98
Description: Jupyter notebook anaconda.ipynb
Compute Environment: Ubuntu 18.04 (Deprecated)
In [32]:
import sys print(sys.executable) sys.version
/ext/anaconda3/bin/python3
'3.5.4 | packaged by conda-forge | (default, Dec 9 2017, 16:18:50) \n[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]'
In [33]:
import cvxpy cvxpy.__version__
'0.4.8'
In [34]:
import pandas_datareader as pdr from pandas_datareader import data, wb pdr.__version__
'0.6.0'
In [35]:
import geopandas geopandas.__version__
'0.3.0'
In [36]:
import cartopy cartopy.__version__
'0.16.0'
In [37]:
import rasterstats as ra ra.__version__
'0.12.1'
In [38]:
import scipy scipy.__version__
'1.0.0'
In [39]:
import sklearn sklearn.__version__
'0.19.1'
In [40]:
import pyximport; pyximport.install() import scipy_special scipy_special.f(1.2, 3.2)
0.9207537886523123
In [41]:
def f(x): return 2*x +1 def g(a, n): b = f(a) for i in range(n): b = f(a) + f(b) return b
In [42]:
%load_ext line_profiler
The line_profiler extension is already loaded. To reload it, use: %reload_ext line_profiler
In [43]:
%lprun -f g g(5, 100)
Timer unit: 1e-06 s Total time: 0.000585 s File: <ipython-input-41-e4e240bf24fd> Function: g at line 3 Line # Hits Time Per Hit % Time Line Contents ============================================================== 3 def g(a, n): 4 1 7.0 7.0 1.2 b = f(a) 5 101 102.0 1.0 17.4 for i in range(n): 6 100 475.0 4.8 81.2 b = f(a) + f(b) 7 1 1.0 1.0 0.2 return b
In [44]:
%lprun -f f g(5, 100)
Timer unit: 1e-06 s Total time: 7.8e-05 s File: <ipython-input-41-e4e240bf24fd> Function: f at line 1 Line # Hits Time Per Hit % Time Line Contents ============================================================== 1 def f(x): 2 201 78.0 0.4 100.0 return 2*x +1
In [45]:
!hostname
project-20e4a191-73ea-4921-80e9-0a5d792fc511
In [46]:
4+4
8
In [47]:
2+2+5
9
In [48]:
import sys; sys.executable
'/ext/anaconda3/bin/python3'

0x  dx\int_0^\infty x\; \mathrm{d}x

In [49]:
import numpy as np; np; np.__version__
'1.12.1'
In [50]:
import pandas as pd
In [51]:
import numba print(numba) numba.__version__
<module 'numba' from '/ext/anaconda3/lib/python3.5/site-packages/numba/__init__.py'>
'0.36.2'
In [52]:
def faster(x, y): a = 0.0 for i in range(x): for j in range(i, x): b = a a += y * .2 a -= y * .1 a = (a + b) / 2. return a
In [53]:
%timeit faster(2222, 1.111)
500 ms ± 97.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [54]:
import numba faster2 = numba.autojit(faster)
In [55]:
%timeit faster2(2222, 1.111)
11.3 ms ± 501 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Test

In [ ]:
In [56]:
def f2(x, y): k = 0 for i in range(x): for j in range(y): k += i / x + j / y return k
In [57]:
%timeit f2(200, 300)
8.09 ms ± 1.28 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
In [58]:
@numba.jit(nopython=True, nogil=True) def f(x, y): k = 0 for i in range(x): for j in range(y): k += i / x + j / y return k
In [ ]:
In [59]:
%timeit f(200, 300)
107 µs ± 2.97 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
In [60]:
%matplotlib inline import matplotlib.pyplot as plt
In [61]:
plt.plot([f(x, 2.2) for x in range(1000)])
[<matplotlib.lines.Line2D at 0x7f8421158208>]
In [62]:
np.__version__
'1.12.1'
In [ ]: