PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/earworm/utils.py

http://echo-nest-remix.googlecode.com/
Python | 23 lines | 6 code | 3 blank | 14 comment | 6 complexity | f01080bf76315217ec36f470658c0762 MD5 | raw file
 1#!/usr/bin/env python
 2# encoding: utf-8
 3"""
 4utils.py
 5
 6Created by Jason Sundram, on 2010-04-05.
 7"""
 8
 9def flatten(l):
10    """ Converts a list of tuples to a flat list.
11        e.g. flatten([(1,2), (3,4)]) => [1,2,3,4]
12    """
13    return [item for pair in l for item in pair]
14
15def tuples(l, n=2):
16    """ returns n-tuples from l.
17        e.g. tuples(range(4), n=2) -> [(0, 1), (1, 2), (2, 3)]
18    """
19    return zip(*[l[i:] for i in range(n)])
20
21def rows(m):
22    """returns the # of rows in a numpy matrix"""
23    return m.shape[0]