Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python's Future in Science

Python's Future in Science

My opening keynote for the Science and Data miniconf at PyCon Australia 2016.

https://2016.pycon-au.org/schedule/200/view_talk?day=friday

Juan Nunez-Iglesias

August 12, 2016
Tweet

Other Decks in Programming

Transcript

  1. Python's Future in Science Juan Nunez-Iglesias Victorian Life Sciences Computation

    Initiative (VLSCI) University of Melbourne at PyCon Australia 2016, Melbourne
  2. import numpy as np from scipy.stats import mstats def quantile_normalise(X):

    quantiles = np.mean(np.sort(X, axis=0), axis=1) ranks = mstats.rankdata(X, axis=0).astype(int) Xnorm = quantiles[ranks] return Xnorm
  3. flights %>% group_by(year, month, day) %>% select(arr_delay) %>% summarise(arrival.delay =

    median(arr_delay, na.rm = TRUE), num.flights = n()) %>% arrange(year, month, day) %>% mutate(date = date_from_tup(year, month, day), weekday = weekday_from_tup(year, month, day)) %>% ggplot(aes(y=arrival.delay, x=date, colour=weekday)) + geom_point() + scale_color_brewer(type="qual")
  4. −25 0 25 50 Jan 2013 Apr 2013 Jul 2013

    Oct 2013 Jan 2014 date arrival.delay weekday Friday Monday Saturday Sunday Thursday Tuesday Wednesday
  5. fibonacci 0 = 0 fibonacci 1 = 1 fibonacci n

    = fibonacci (n - 1) + fibonacci (n - 2)
  6. fibonacci 0 = 0 fibonacci 1 = 1 fibonacci n

    = fibonacci (n - 1) + fibonacci (n - 2) fibonacci = 0 : 1 : zipWith (+) fibonacci (tail fibonacci)
  7. import numpy as np from scipy.stats import mstats def quantile_normalise(X):

    quantiles = np.mean(np.sort(X, axis=0), axis=1) ranks = mstats.rankdata(X, axis=0).astype(int) Xnorm = quantiles[ranks] return Xnorm
  8. Conn = (Adj + Adj.T) / 2 degs = np.ravel(Conn.sum(axis=0))

    Degs = sparse.diags(1 / np.sqrt(degs)) Lap = Degs - Conn Q = Degs @ Lap @ Degs eigvals, eigvecs = eigsh(Q, k=3, which='SM') eigvecs = eigvecs[:, np.argsort(eigvals)] _, x, y = (Degs @ eigvecs).T
  9. def f(x): y = x**4 - 3*x return y def

    integrate_f(a, b, n): dx = (b - a) / n dx2 = dx / 2 s = f(a) * dx2 for i in range(1, n): s += f(a + i * dx) * dx s += f(b) * dx2 return s http://bit.ly/aspp-cython
  10. def f(x): y = x**4 - 3*x return y def

    integrate_f(a, b, n): dx = (b - a) / n dx2 = dx / 2 s = f(a) * dx2 for i in range(1, n): s += f(a + i * dx) * dx s += f(b) * dx2 return s cdef double f(double x): cdef double y = x**4 - 3*x return y def integrate_f(double a, double b, int n): cdef: double dx = (b - a) / n double dx2 = dx / 2 double s = f(a) * dx2 int i = 0 for i in range(1, n): s += f(a + i * dx) * dx s += f(b) * dx2 return s http://bit.ly/aspp-cython
  11. function quadratic(a, sqr_term, b) return (-b + sqr_term) / 2a

    end function quadratic2(a, b, c) sqr_term = sqrt(b^2-4a*c) r1 = quadratic(a, sqr_term, b) r2 = quadratic(a, -sqr_term, b) return r1, r2 end adapted from https://samuelcolvin.github.io/JuliaByExample
  12. def euclidean_distance(a, b): n = len(a) sqdist = 0 for

    i in range(n): d = a[i] - b[i] sqdist += d * d return np.sqrt(sqdist)
  13. def f(x): y = x**4 - 3*x return y def

    integrate_f(a, b, n): dx = (b - a) / n dx2 = dx / 2 s = f(a) * dx2 for i in range(1, n): s += f(a + i * dx) * dx s += f(b) * dx2 return s
  14. def f(x): y = x**4 - 3*x return y def

    integrate_f(a, b, n): dx = (b - a) / n dx2 = dx / 2 s = f(a) * dx2 for i in range(1, n): s += f(a + i * dx) * dx s += f(b) * dx2 return s import numba @numba.jit(nopython=True) def f(x): y = x**4 - 3*x return y @numba.jit(nopython=True) def integrate_f(a, b, n): dx = (b - a) / n dx2 = dx / 2 s = f(a) * dx2 for i in range(1, n): s += f(a + i * dx) * dx s += f(b) * dx2 return s
  15. def euclidean_distance(a, b): n = len(a) sqdist = 0 for

    i in range(n): d = a[i] - b[i] sqdist += d * d return np.sqrt(sqdist)
  16. def euclidean_distance(a, b): n = len(a) sqdist = 0 for

    i in range(n): d = a[i] - b[i] sqdist += d * d return np.sqrt(sqdist) https://jakevdp.github.io/blog/2012/09/20/why-python-is-the-last/