Mercurial > hg > numerics
changeset 51:e7e49b46832b
make this function semi-meaningful
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 19 Jan 2015 12:51:25 -0800 |
parents | e39643d18d82 |
children | 37838ae694d2 |
files | numerics/data.py |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/numerics/data.py Mon Jan 19 12:45:06 2015 -0800 +++ b/numerics/data.py Mon Jan 19 12:51:25 2015 -0800 @@ -6,7 +6,11 @@ from collections import OrderedDict -__all__ = ['ColumnNumberException', 'ColumnLengthException', 'Rows', 'Columns'] +__all__ = ['ColumnNumberException', + 'ColumnLengthException', + 'transpose', + 'Rows', + 'Columns'] class ColumnNumberException(Exception): @@ -25,10 +29,12 @@ if not array: return array # nothing to do - n_cols = len(array[0]) - retval = [[]] * n_cols + n_cols = set([len(row) for row in array]) + if len(n_cols) != 1: + raise Exception("Differing number of columns found: {}".format(', '.join(sorted(n_cols)))) + return zip(*array) - # XXX this is a nothing function; we shouldn't use this + class ColumnLengthException(ColumnNumberException): """