#63EasyLists & Tuples· Nested Lists
NumPy-Style Array Operations
Input format
`values`: a list of integers. `rows`, `cols`: positive integers.
Output format
A dictionary as described, or a dictionary with a single `error` key.
Examples
Input: values = [1,2,3,4,5,6], rows = 2, cols = 3
Output: {"matrix":[[1,2,3],[4,5,6]],"transposed":[[1,4],[2,5],[3,6]],"row_max":[3,6],"col_sums":[5,7,9],"above_mean":[4,5,6]}
The mean is 3.5, so 4, 5 and 6 are above it.
Input: values = [1,2,3,4,5], rows = 2, cols = 3
Output: {"error":"cannot reshape 5 values into 2x3"}
Six slots cannot hold five values.
Constraints
- 1 <= len(values) <= 10^4
- 1 <= rows, cols <= 10^4
- -10^6 <= value <= 10^6
Study first
- #python
- #nested-lists
- #matrices
- #numpy
