(cls, table, feature_names_column="",
                  meta_attr_name="Feature name", feature_name="Feature",
                  remove_redundant_inst=False, progress_callback=None)
Transpose the table.

        :param table: Table - table to transpose
        :param feature_names_column: str - name of (String) meta attribute to
            use for feature names
        :param meta_attr_name: str - name of new meta attribute into which
            feature names are mapped
        :param feature_name: str - default feature name prefix
        :param remove_redundant_inst: bool - remove instance that
            represents feature_names_column
        :param progress_callback: callable - to report the progress
        :return: Table - transposed table
Transpose the table.
Transpose the table .
def transpose(cls, table, feature_names_column="",
                  meta_attr_name="Feature name", feature_name="Feature",
                  remove_redundant_inst=False, progress_callback=None):
        """
        Transpose the table.

        :param table: Table - table to transpose
        :param feature_names_column: str - name of (String) meta attribute to
            use for feature names
        :param meta_attr_name: str - name of new meta attribute into which
            feature names are mapped
        :param feature_name: str - default feature name prefix
        :param remove_redundant_inst: bool - remove instance that
            represents feature_names_column
        :param progress_callback: callable - to report the progress
        :return: Table - transposed table
        """
        if progress_callback is None:
            progress_callback = dummy_callback
        progress_callback(0, "Transposing...")

        if isinstance(feature_names_column, Variable):
            feature_names_column = feature_names_column.name

        self = cls()
        n_cols, self.n_rows = table.X.shape
        old_domain = table.attributes.get("old_domain")
        table_domain_attributes = list(table.domain.attributes)
        attr_index = None
        if remove_redundant_inst:
            attr_names = [a.name for a in table_domain_attributes]
            if feature_names_column and feature_names_column in attr_names:
                attr_index = attr_names.index(feature_names_column)
                self.n_rows = self.n_rows - 1
                table_domain_attributes.remove(
                    table_domain_attributes[attr_index])

        # attributes
        # - classes and metas to attributes of attributes
        # - arbitrary meta column to feature names
        with self.unlocked_reference():
            self.X = table.X.T
            if attr_index is not None:
                self.X = np.delete(self.X, attr_index, 0)
            if feature_names_column:
                names = [str(row[feature_names_column]) for row in table]
                progress_callback(0.1)
                names = get_unique_names_duplicates(names)
                progress_callback(0.3)
                attributes = [ContinuousVariable(name) for name in names]
            else:
                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1
                attributes = [ContinuousVariable(f"{feature_name} {i:0{places}}")
                              for i in range(1, n_cols + 1)]
            progress_callback(0.4)

            if old_domain is not None and feature_names_column:
                for i, _ in enumerate(attributes):
                    if attributes[i].name in old_domain:
                        var = old_domain[attributes[i].name]
                        attr = ContinuousVariable(var.name) if var.is_continuous \
                            else DiscreteVariable(var.name, var.values)
                        attr.attributes = var.attributes.copy()
                        attributes[i] = attr

            def set_attributes_of_attributes(_vars, _table):
                for i, variable in enumerate(_vars):
                    if variable.name == feature_names_column:
                        continue
                    for j, row in enumerate(_table):
                        value = variable.repr_val(row) if np.isscalar(row) \
                            else row[i] if isinstance(row[i], str) \
                            else variable.repr_val(row[i])

                        if value not in MISSING_VALUES:
                            attributes[j].attributes[variable.name] = value

            set_attributes_of_attributes(table.domain.class_vars, table.Y)
            progress_callback(0.5)
            set_attributes_of_attributes(table.domain.metas, table.metas)

            # weights
            self.W = np.empty((self.n_rows, 0))

            def get_table_from_attributes_of_attributes(_vars, _dtype=float):
                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)
                for i, _attr in enumerate(table_domain_attributes):
                    for j, _var in enumerate(_vars):
                        val = str(_attr.attributes.get(_var.name, ""))
                        if not _var.is_string:
                            val = np.nan if val in MISSING_VALUES else \
                                _var.values.index(val) if \
                                    _var.is_discrete else float(val)
                        T[i, j] = val
                return T

            # class_vars - attributes of attributes to class - from old domain
            class_vars = []
            if old_domain is not None:
                class_vars = old_domain.class_vars
            self.Y = get_table_from_attributes_of_attributes(class_vars)

            # metas
            # - feature names and attributes of attributes to metas
            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []
            if meta_attr_name not in [m.name for m in table.domain.metas] and \
                    table_domain_attributes:
                self.metas = np.array([[a.name] for a in table_domain_attributes],
                                      dtype=object)
                metas.append(StringVariable(meta_attr_name))

            names = chain.from_iterable(list(attr.attributes)
                                        for attr in table_domain_attributes)
            names = sorted(set(names) - {var.name for var in class_vars})
            progress_callback(0.6)

            def guessed_var(i, var_name):
                orig_vals = M[:, i]
                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)
                values, variable = Orange.data.io.sanitize_variable(
                    val_map, vals, orig_vals, var_type, {}, name=var_name)
                M[:, i] = values
                return variable

            _metas = [StringVariable(n) for n in names]
            if old_domain is not None:
                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]
            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)
            progress_callback(0.7)
            if old_domain is None:
                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]
            if _metas:
                self.metas = np.hstack((self.metas, M))
                metas.extend(_metas)

            self.domain = Domain(attributes, class_vars, metas)
            progress_callback(0.9)
            cls._init_ids(self)
            self.attributes = table.attributes.copy()
            self.attributes["old_domain"] = table.domain
            progress_callback(1)
            return self
def transpose ( cls , table , feature_names_column = "" , meta_attr_name = "Feature name" , feature_name = "Feature" , remove_redundant_inst = False , progress_callback = None ) : if progress_callback is None : progress_callback = dummy_callback progress_callback ( 0 , "Transposing..." ) if isinstance ( feature_names_column , Variable ) : feature_names_column = feature_names_column . name self = cls ( ) n_cols , self . n_rows = table . X . shape old_domain = table . attributes . get ( "old_domain" ) table_domain_attributes = list ( table . domain . attributes ) attr_index = None if remove_redundant_inst : attr_names = [ a . name for a in table_domain_attributes ] if feature_names_column and feature_names_column in attr_names : attr_index = attr_names . index ( feature_names_column ) self . n_rows = self . n_rows - 1 table_domain_attributes . remove ( table_domain_attributes [ attr_index ] ) # attributes # - classes and metas to attributes of attributes # - arbitrary meta column to feature names with self . unlocked_reference ( ) : self . X = table . X . T if attr_index is not None : self . X = np . delete ( self . X , attr_index , 0 ) if feature_names_column : names = [ str ( row [ feature_names_column ] ) for row in table ] progress_callback ( 0.1 ) names = get_unique_names_duplicates ( names ) progress_callback ( 0.3 ) attributes = [ ContinuousVariable ( name ) for name in names ] else : places = int ( np . ceil ( np . log10 ( n_cols ) ) ) if n_cols else 1 attributes = [ ContinuousVariable ( f"{feature_name} {i:0{places}}" ) for i in range ( 1 , n_cols + 1 ) ] progress_callback ( 0.4 ) if old_domain is not None and feature_names_column : for i , _ in enumerate ( attributes ) : if attributes [ i ] . name in old_domain : var = old_domain [ attributes [ i ] . name ] attr = ContinuousVariable ( var . name ) if var . is_continuous else DiscreteVariable ( var . name , var . values ) attr . attributes = var . attributes . copy ( ) attributes [ i ] = attr def set_attributes_of_attributes ( _vars , _table ) : for i , variable in enumerate ( _vars ) : if variable . name == feature_names_column : continue for j , row in enumerate ( _table ) : value = variable . repr_val ( row ) if np . isscalar ( row ) else row [ i ] if isinstance ( row [ i ] , str ) else variable . repr_val ( row [ i ] ) if value not in MISSING_VALUES : attributes [ j ] . attributes [ variable . name ] = value set_attributes_of_attributes ( table . domain . class_vars , table . Y ) progress_callback ( 0.5 ) set_attributes_of_attributes ( table . domain . metas , table . metas ) # weights self . W = np . empty ( ( self . n_rows , 0 ) ) def get_table_from_attributes_of_attributes ( _vars , _dtype = float ) : T = np . empty ( ( self . n_rows , len ( _vars ) ) , dtype = _dtype ) for i , _attr in enumerate ( table_domain_attributes ) : for j , _var in enumerate ( _vars ) : val = str ( _attr . attributes . get ( _var . name , "" ) ) if not _var . is_string : val = np . nan if val in MISSING_VALUES else _var . values . index ( val ) if _var . is_discrete else float ( val ) T [ i , j ] = val return T # class_vars - attributes of attributes to class - from old domain class_vars = [ ] if old_domain is not None : class_vars = old_domain . class_vars self . Y = get_table_from_attributes_of_attributes ( class_vars ) # metas # - feature names and attributes of attributes to metas self . metas , metas = np . empty ( ( self . n_rows , 0 ) , dtype = object ) , [ ] if meta_attr_name not in [ m . name for m in table . domain . metas ] and table_domain_attributes : self . metas = np . array ( [ [ a . name ] for a in table_domain_attributes ] , dtype = object ) metas . append ( StringVariable ( meta_attr_name ) ) names = chain . from_iterable ( list ( attr . attributes ) for attr in table_domain_attributes ) names = sorted ( set ( names ) - { var . name for var in class_vars } ) progress_callback ( 0.6 ) def guessed_var ( i , var_name ) : orig_vals = M [ : , i ] val_map , vals , var_type = Orange . data . io . guess_data_type ( orig_vals ) values , variable = Orange . data . io . sanitize_variable ( val_map , vals , orig_vals , var_type , { } , name = var_name ) M [ : , i ] = values return variable _metas = [ StringVariable ( n ) for n in names ] if old_domain is not None : _metas = [ m for m in old_domain . metas if m . name != meta_attr_name ] M = get_table_from_attributes_of_attributes ( _metas , _dtype = object ) progress_callback ( 0.7 ) if old_domain is None : _metas = [ guessed_var ( i , m . name ) for i , m in enumerate ( _metas ) ] if _metas : self . metas = np . hstack ( ( self . metas , M ) ) metas . extend ( _metas ) self . domain = Domain ( attributes , class_vars , metas ) progress_callback ( 0.9 ) cls . _init_ids ( self ) self . attributes = table . attributes . copy ( ) self . attributes [ "old_domain" ] = table . domain progress_callback ( 1 ) return self