Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/article/advanced/numpy_exercises_for_data_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -2143,8 +2143,13 @@ a = np.array([1, 3, 7, 1, 2, 6, 0, 1])

```python
a = np.array([1, 3, 7, 1, 2, 6, 0, 1])
#solution1
doublediff = np.diff(np.sign(np.diff(a)))
peak_locations = np.where(doublediff == -2)[0] + 1

#solution2
peak_locations = np.array([i for i in range(1,a.size - 1) if a[i]>a[i-1] and a[i] > a[i+1]])

peak_locations
# > array([2, 5])
```
Expand Down Expand Up @@ -2385,4 +2390,4 @@ print(gen_strides(np.arange(15), stride_len=2, window_len=4))

## 文章出处

由NumPy中文文档翻译,原作者为 machinelearningplus.com,翻译至:[https://www.machinelearningplus.com/python/101-numpy-exercises-python/](https://www.machinelearningplus.com/python/101-numpy-exercises-python/)
由NumPy中文文档翻译,原作者为 machinelearningplus.com,翻译至:[https://www.machinelearningplus.com/python/101-numpy-exercises-python/](https://www.machinelearningplus.com/python/101-numpy-exercises-python/)