def transform_tree(array): if isinstance(array[0], tuple): tree = np.array([]) for tupl in array: n = Node() n.set_name(tupl[0]) n.set_freq(tupl[1]) tree = np.append(tree, n) else : tree = np.array(array) return tree