I like this numpy solution. It's very clean and concise. =)