##### `np.repeat(a, repeats, axis=None)` **功能简介:** - 用于沿指定的轴重复数组中的元素。 **参数说明:** - `a`:要重复的数组。 - `repeats`:一个整数或整数数组,指定每个元素重复的次数。 - `axis`:指定要重复的轴。默认为 `None`,表示将数组展平后重复。 **返回值:** - 返回一个新数组,其中包含重复元素后的结果。 **两个用法实例:** 1. **在一维数组中重复元素:** ```python import numpy as np arr = np.array([1, 2, 3]) repeat_count = 3 repeated_arr = np.repeat(arr, repeat_count) print(repeated_arr) # 输出:[1 1 1 2 2 2 3 3 3] ``` 2. **在多维数组中沿指定轴重复元素:** ```python import numpy as np arr = np.array([[1, 2], [3, 4]]) repeat_count = 2 repeated_arr = np.repeat(arr, repeat_count, axis=1) print(repeated_arr) # 输出: # [[1 1 2 2] # [3 3 4 4]] ```