Diagonal From Values
Return a square 2-D array with len(values) rows and columns that has the numbers of values down its main diagonal (top-left to bottom-right) and 0 everywhere else. Hint: np.diag.
Example 1
values [4,5,6]
returns [[4,0,0],[0,5,0],[0,0,6]]
Row 0 is [4, 0, 0], row 1 is [0, 5, 0], row 2 is [0, 0, 6].
Constraints
1 <= len(values) <= 8
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Evenly SpacedBeginner
- Every Other SumBeginner
- Hottest DayBeginner
- Lower Triangle TotalBeginner
- Median ScoreBeginner
- Multiples Up ToBeginner
- Overlap CountBeginner
- Pass or FailBeginner