Pair Differences
arr has an even length and is made of consecutive pairs: items 0 and 1, items 2 and 3, and so on. Return a list with one number per pair: the second item minus the first. Hint: arr.reshape(-1, 2).
Example 1
arr [1,5,10,4]
returns [4,-6]
The pairs are (1, 5) and (10, 4), giving 4 and -6.
Constraints
2 <= len(arr) <= 60andlen(arr)is even
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Percent ChangeEasy
- Row RangesEasy
- Rows With a ZeroEasy
- Rows of WidthEasy
- Runner-Up per RowEasy
- Running Total per ColumnEasy
- Scale to Zero OneEasy
- Second LargestEasy