在python中写出以下问题的解决方案:给定二进制树的根,以数组的形式返回每个层次的节点的平均值.
Here is a possible solution in Python:

```
class Solution:
    def averageOfLevels(self, root: TreeNode) -> List[float]:
        # Initialize a queue to perform a level-order traversal
        queue = [root]
        
        # Initialize an empty list to store the result
        result = []
        
        while queue:
            # Compute the average value of the nodes on the current level
            level_sum = 0
            level_size = len(queue)
            
            for i in range(level_size):
                node = queue.pop(0)
                level_sum += node.val
                
                if node.left:
                    queue.append(node.left)
                if node.right:
                    queue.append(node.right)
                    
            result.append(level_sum / level_size)
            
        return result
```

In this solution, we use a queue to perform a level-order traversal of the binary tree. At each level, we compute the sum and size of the nodes on the level, and then compute the average value. Finally, we append the average value to the result list and move on to the next level. The time complexity of this solution is O(n), where n is the number of nodes in the tree, since we visit each node exactly once.