Blog Archives

Machine Learning in Action

A couple months ago I briefly reviewed Machine Learning for Hackers by Drew Conway and John Myles White. Today I’m looking at Machine Learning in Action by Peter Harrington and comparing the two books. Both books are about the same

Tagged with:
Posted in Python

Solutions to knight's random walk

My previous post asked this question: Start a knight at a corner square of an otherwise-empty chessboard. Move the knight at random by choosing uniformly from the legal knight-moves at each step. What is the mean number of moves until

Tagged with: ,
Posted in Python

Python as a Lisp dialect

From Peter Norvig: Basically, Python can be seen as a dialect of Lisp with “traditional” syntax … Python supports all of Lisp’s essential features except macros, and you don’t miss macros all that much because it does have eval, and

Tagged with: ,
Posted in Python

Math languages vs. application languages

Last Friday I posted on @SciPyTip a summary of why I like SciPy, the scientific programming library for Python. I’d rather do math in a general-purpose language than try to do general-purpose programming in a math language. Mathematical software is

Tagged with: ,
Posted in Python

SciPy integration misunderstanding

Today I needed to compute an integral similar to this: I used the following SciPy code to compute the integral: from scipy.integrate import quad def f(x): return 0.01*x**-3 integral, error = quad(f, 1000, sp.inf, epsrel = 1e-6) print integral, error

Tagged with: , ,
Posted in Python

Approximating Earth as a sphere

Isaac Newton suggested in 1687 that the earth is not a perfectly round sphere but rather an ellipsoid, and he was right. But since our planet is roughly a sphere, it’s often useful to approximate it by a sphere. So

Tagged with: , ,
Posted in Math, Python, Science

Mixing R, Python, and Perl in 14 lines of code

This is a continuation of my previous post, Running Python and R inside Emacs. That post shows how to execute independent code blocks in Emacs org-mode. This post illustrates calling one code block from another, each written in a different

Tagged with: ,
Posted in Python

Running Python and R inside Emacs

Emacs org-mode lets you manage blocks of source code inside a text file. You can execute these blocks and have the output display in your text file. Or you could export the file, say to HTML or PDF, and show

Tagged with: , , , ,
Posted in Python

Example of not inverting a matrix: optimization

People are invariably surprised when they hear it’s hardly ever necessary to invert a matrix. It’s very often necessary solve linear systems of the form Ax = b, but in practice you almost never do this by inverting A. This

Tagged with: , ,
Posted in Python

How to compute jinc(x)

The function jinc(x) that I wrote about yesterday is almost trivial to implement, but not quite. I’ll explain why it’s not quite as easy as it looks and how one might implement it in C and Python.

Tagged with: ,
Posted in Python

The Python ecosystem

The hard part about getting started with Python is not the language but the ecosystem. It’s easy to find good references on the Python language, but it’s harder to learn what packages are available, how to install them, etc. That

Tagged with:
Posted in Python

Python is a voluntary language

People who write Python choose to write Python. I don’t hear people say “I use Python at work because I have to, but I’d rather be writing Java.” But often I do hear people say they’d like to use Python

Tagged with: ,
Posted in Python, Software development

Leading digits of factorials

Suppose you take factorials of a lot of numbers and look at the leading digit of each result. You could argue that there’s no apparent reason that any digit would be more common than any other, so you’d expect each

Tagged with: , , ,
Posted in Python

Benford’s law and SciPy

Imagine you picked up a dictionary and found that the pages with A’s were dirty and the Z’s were clean. In between there was a gradual transition with the pages becoming cleaner as you progressed through the alphabet. You might

Tagged with: ,
Posted in Python

Physical constants and factorials

The previous post mentioned that Avogadro’s constant is approximately 24!. Are there other physical constants that are nearly factorials?

Tagged with: , ,
Posted in Python