def get_frequency(train):
    """
    Get the mean frequency of a spike train. Assumes time is in ms.
    """
    try:
        length = len(train)
        first = train[0]
        last = train[-1]            
        return float(length-1)/float(last-first)*1000.
    except: # On any error, just return 0
        return 0