# Implement the function distance_error(flat_node_pos, path_lengths) that takes a 1D numpy array flat_node_pos of the form [x0 y0

## Question:

Implement the function distance_error(flat_node_pos, path_lengths) that takes a 1D numpy array flat_node_pos of the form [x0 y0 x1 y1 ...] and a nested dictionary path_lengths with the nested keys as node indices of the start and end of the path and the values as the length of the corresponding path from the start node to the end node (path_lengths will be computed in the next function distance_layout through all_pairs_shortest_path_length() method). The function should return the sum of the squares of differences between the path lengths in path_lengths and the geometric distances between nodes in flat_node_pos.

Here is the template code to start with:

def distance_error(flat_node_pos, path_lengths):

"""

Input: 1D numpy array flat_node_pos of the form [x0 y0 x1 y1 ...],

nested dictionary path_lengths of path lengths keyed by node indices

Output: Sum of squares of differences between path lengths

and geometric distances between pairs of nodes (based on values in flat_node_pos)

Note: path_lengths will be computed via all_pairs_shortest_path_length()

**Related Book For**

## Management Accounting Information for Decision-Making and Strategy Execution

ISBN: 978-0137024971

6th Edition

Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young

**Posted Date:**