utils/framework.py
def data_transpose(self, data: list[Any], dim: int = 0) -> Any:
        """
        Convert list of elements into elements' structure.
        Example:
            (no inner / undefined structure)
            [1,2,3,4,5]
            --> [1,2,3,4,5]

            (inner structure is a list)
            [[1,2],[3,4],[5,6]]
            --> [[1,3,5], [2,4,6]]

            (inner structure is a tuple)
            [(1,2),(3,4),(5,6),...]
            --> ([1,3,5,...], [2,4,6,...])

            (inner structure is a dict)
            [
                {a:1,b:2,c:3},
                {a:2,b:3,c:4},
                {a:3,b:4,c:5},
            ]
            --> {a: [1,2,3], b: [2,3,4], c: [3,4,5]}

            (nested structure)
            [
                (1,(2,3),4),
                (1,[2,3],4),
                (1,[2,3],4)
            ]
            --> (
                    [1, 1, 1],
                    [(2, 3), [2, 3], [2, 3]],
                    [4, 4, 4]
                )
        """
        if isinstance(data[0], dict):
            out_dict = {}
            for k in data[0]:
                out_dict[k] = []
            for item in data:
                for k in item:
                    out_dict[k].append(item[k])
            return out_dict
        elif isinstance(data[0], tuple):
            out_tuple = []
            for col in range(len(data[0])):
                out_col = []
                for item in data:
                    out_col.append(item[col])
                out_tuple.append(out_col)
            out_tuple = tuple(out_tuple)
            return out_tuple
        elif isinstance(data[0], list):
            out_list = []
            for col in range(len(data[0])):
                out_col = []
                for item in data:
                    out_col.append(item[col])
                out_list.append(out_col)
            return out_list
        elif isinstance(data[0], torch.Tensor):
            return torch.cat(data, dim=dim)
        elif isinstance(data[0], np.ndarray):
            return np.concatenate(data, axis=dim)
        else:
            return data

        Convert list of elements into elements' structure.
        Example:
            (no inner / undefined structure)
            [1,2,3,4,5]
            --> [1,2,3,4,5]

            (inner structure is a list)
            [[1,2],[3,4],[5,6]]
            --> [[1,3,5], [2,4,6]]

            (inner structure is a tuple)
            [(1,2),(3,4),(5,6),...]
            --> ([1,3,5,...], [2,4,6,...])

            (inner structure is a dict)
            [
                {a:1,b:2,c:3},
                {a:2,b:3,c:4},
                {a:3,b:4,c:5},
            ]
            --> {a: [1,2,3], b: [2,3,4], c: [3,4,5]}

            (nested structure)
            [
                (1,(2,3),4),
                (1,[2,3],4),
                (1,[2,3],4)
            ]
            --> (
                    [1, 1, 1],
                    [(2, 3), [2, 3], [2, 3]],
                    [4, 4, 4]
                )
        
Convert list of elements into elements' structure.
Convert list of elements into elements ' structure .
def data_transpose(self, data: list[Any], dim: int = 0) -> Any:
        if isinstance(data[0], dict):
            out_dict = {}
            for k in data[0]:
                out_dict[k] = []
            for item in data:
                for k in item:
                    out_dict[k].append(item[k])
            return out_dict
        elif isinstance(data[0], tuple):
            out_tuple = []
            for col in range(len(data[0])):
                out_col = []
                for item in data:
                    out_col.append(item[col])
                out_tuple.append(out_col)
            out_tuple = tuple(out_tuple)
            return out_tuple
        elif isinstance(data[0], list):
            out_list = []
            for col in range(len(data[0])):
                out_col = []
                for item in data:
                    out_col.append(item[col])
                out_list.append(out_col)
            return out_list
        elif isinstance(data[0], torch.Tensor):
            return torch.cat(data, dim=dim)
        elif isinstance(data[0], np.ndarray):
            return np.concatenate(data, axis=dim)
        else:
            return data
def data_transpose ( self , data : list [ Any ] , dim : int = 0 ) -> Any : if isinstance ( data [ 0 ] , dict ) : out_dict = { } for k in data [ 0 ] : out_dict [ k ] = [ ] for item in data : for k in item : out_dict [ k ] . append ( item [ k ] ) return out_dict elif isinstance ( data [ 0 ] , tuple ) : out_tuple = [ ] for col in range ( len ( data [ 0 ] ) ) : out_col = [ ] for item in data : out_col . append ( item [ col ] ) out_tuple . append ( out_col ) out_tuple = tuple ( out_tuple ) return out_tuple elif isinstance ( data [ 0 ] , list ) : out_list = [ ] for col in range ( len ( data [ 0 ] ) ) : out_col = [ ] for item in data : out_col . append ( item [ col ] ) out_list . append ( out_col ) return out_list elif isinstance ( data [ 0 ] , torch . Tensor ) : return torch . cat ( data , dim = dim ) elif isinstance ( data [ 0 ] , np . ndarray ) : return np . concatenate ( data , axis = dim ) else : return data
Convert list of elements into elements' structure.
Convert list of elements into elements ' structure .
"""
        Convert list of elements into elements' structure.
        Example:
            (no inner / undefined structure)
            [1,2,3,4,5]
            --> [1,2,3,4,5]

            (inner structure is a list)
            [[1,2],[3,4],[5,6]]
            --> [[1,3,5], [2,4,6]]

            (inner structure is a tuple)
            [(1,2),(3,4),(5,6),...]
            --> ([1,3,5,...], [2,4,6,...])

            (inner structure is a dict)
            [
                {a:1,b:2,c:3},
                {a:2,b:3,c:4},
                {a:3,b:4,c:5},
            ]
            --> {a: [1,2,3], b: [2,3,4], c: [3,4,5]}

            (nested structure)
            [
                (1,(2,3),4),
                (1,[2,3],4),
                (1,[2,3],4)
            ]
            --> (
                    [1, 1, 1],
                    [(2, 3), [2, 3], [2, 3]],
                    [4, 4, 4]
                )
        """
self
data
list[Any]
dim
int
examples
None