set Mac for python

Update: Now I would recommend just anaconda python

To be cool in a coffee shop I bought a mac and then I become dumb at work.

Gladly I find these tips on setting up a mac for python

http://hackercodex.com/guide/mac-osx-mavericks-10.9-configuration/

http://hackercodex.com/guide/python-development-environment-on-mac-osx/

Advertisements

easy_install does not work after distribute upgrade

I tried to upgrade matplotlib which asked me to upgrade distribute. I upgraded distribute and then easy_install does not work…… It is solved by the following

1. Check your /usr/bin and /usr/local/bin for easy_install installations and remove any old script:

sudo rm /usr/bin/easy_install*

sudo rm /usr/local/bin/easy_install*

2. Download and run distribute:

curl -O http://python-distribute.org/distribute_setup.py

sudo python distribute_setup.py

sudo rm distribute_setup.py

Copy from

Sample with replacement

random.sample() samples without replacement. I find this piece of code by Sean Ross which samples with replacement.

# credit author(s) of random.py
import random
import itertools

def sample_wr(population, k):
    "Chooses k random elements (with replacement) from a population"
    n = len(population)
    _random, _int = random.random, int  # speed hack 
    return [population[_int(_random() * n)] for i in itertools.repeat(None, k)]