# AUTOGENERATED! DO NOT EDIT! File to edit: dev/06_utils.ipynb (unless otherwise specified).

__all__ = ['Table']

# Cell
import numpy as np

# Cell
class Table:
    """
    Class that prints a 2D table of numpy data.
    """
    def __init__(self, data, col_names=[], h_space=0):
        """
        Constructor.
        Args
            data: 1D or 2D matrix of data (nested list or np array)
            col_names: column names
            h_space: horizontal space between columns. if 0 it is calculated based on the longest string/
        """
        assert isinstance(col_names, list), "col_names must be a list"
        assert len(data.shape) <= 2, "data must be 1 or 2 dimentional."
        self.data = data
        self.col_names = col_names
        self.h_space = h_space

    def __repr__(self):
        if isinstance(self.data, np. ndarray):
            data = [self.col_names] + list(zip(*self.data.tolist()))
        else:
            data = [self.col_names] + list(zip(self.data))

        if self.h_space <= 0:
            h_space = len(max(max(data, key=len), key=len))
        else:
            h_space = self.h_space

        table = ''
        for i, d in enumerate(data):
            table += '|'.join(str(x).ljust(h_space) for x in d)
            table += '\n'
            if i == 0 and len(self.col_names) > 0:
                table += '-' * len(table) + '\n'
        return table

# AUTOGENERATED! DO NOT EDIT! File to edit: dev/06_utils.ipynb (unless otherwise specified).

__all__ = ['Table']

# Cell
import numpy as np

# Cell
class Table:
    """
    Class that prints a 2D table of numpy data.
    """
    def __init__(self, data, col_names=[], h_space=0):
        """
        Constructor.
        Args
            data: 1D or 2D matrix of data (nested list or np array)
            col_names: column names
            h_space: horizontal space between columns. if 0 it is calculated based on the longest string/
        """
        assert isinstance(col_names, list), "col_names must be a list"
        assert len(data.shape) <= 2, "data must be 1 or 2 dimentional."
        self.data = data
        self.col_names = col_names
        self.h_space = h_space

    def __repr__(self):
        if isinstance(self.data, np. ndarray):
            data = [self.col_names] + list(zip(*self.data.tolist()))
        else:
            data = [self.col_names] + list(zip(self.data))

        if self.h_space <= 0:
            h_space = len(max(max(data, key=len), key=len))
        else:
            h_space = self.h_space

        table = ''
        for i, d in enumerate(data):
            table += '|'.join(str(x).ljust(h_space) for x in d)
            table += '\n'
            if i == 0 and len(self.col_names) > 0:
                table += '-' * len(table) + '\n'
        return table

# AUTOGENERATED! DO NOT EDIT! File to edit: dev/06_utils.ipynb (unless otherwise specified). # Cell # Cell Class that prints a 2D table of numpy data. Constructor.         Args             data: 1D or 2D matrix of data (nested list or np array)             col_names: column names             h_space: horizontal space between columns. if 0 it is calculated based on the longest string/