/examples/earworm/utils.py

http://echo-nest-remix.googlecode.com/ · Python · 23 lines · 6 code · 3 blank · 14 comment · 3 complexity · f01080bf76315217ec36f470658c0762 MD5 · raw file

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. """
  4. utils.py
  5. Created by Jason Sundram, on 2010-04-05.
  6. """
  7. def flatten(l):
  8. """ Converts a list of tuples to a flat list.
  9. e.g. flatten([(1,2), (3,4)]) => [1,2,3,4]
  10. """
  11. return [item for pair in l for item in pair]
  12. def tuples(l, n=2):
  13. """ returns n-tuples from l.
  14. e.g. tuples(range(4), n=2) -> [(0, 1), (1, 2), (2, 3)]
  15. """
  16. return zip(*[l[i:] for i in range(n)])
  17. def rows(m):
  18. """returns the # of rows in a numpy matrix"""
  19. return m.shape[0]