Reordering Rows/Columns With clustermap
Brindle & Co compares depots by how far apart they are on a set of measures, giving a square grid where both axes are the same depot list. The chart reorders the rows and the columns so similar depots end up next to each other, which means the layout changes run to run. The summary underneath therefore has to be a figure the reordering cannot move: the total distance between different depots.
Task: Print the total of every cell except those where a depot meets itself.
Input
The first line holds one integer n, the number of depots, where 1 <= n <= 100. Then come n lines, each holding n numbers separated by single spaces: one row of the square grid.
Output
One line holding the total of all the off-diagonal cells, rounded to 2 decimal places. Both halves count: the a-to-b cell and the b-to-a cell are separate cells and are both included.
Example:
Input:
2
1 5
5 1
Output:
10.00
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in