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

/examples/capsule/utils.py

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