def to_distance(matrix, alpha=<NUM_LIT:1>):
matrix = np.array(matrix)<EOL>try:<EOL><INDENT>import scipy.sparse<EOL><DEDENT>except ImportError as e:<EOL><INDENT>print("<STR_LIT>")<EOL>print(str(e))<EOL>raise<EOL><DEDENT>if callable(alpha):<EOL><INDENT>distance_function = alpha<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>a = np.float64(alpha)<EOL>def distance_function(x):<EOL><INDENT>return <NUM_LIT:1> / (x ** (<NUM_LIT:1> / a))<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>print("<STR_LIT>")<EOL>raise<EOL><DEDENT><DEDENT>if hasattr(matrix, '<STR_LIT>'):<EOL><INDENT>distances = scipy.sparse.coo_matrix(matrix)<EOL>distances.data = distance_function(distances.data)<EOL><DEDENT>else:<EOL><INDENT>distances = np.zeros(matrix.shape)<EOL>distances[matrix != <NUM_LIT:0>] = distance_function(<NUM_LIT:1> / matrix[matrix != <NUM_LIT:0>])<EOL><DEDENT>return scipy.sparse.csgraph.floyd_warshall(distances, directed=False)<EOL>
Compute distance matrix from contact data by applying a negative power
    law (alpha) to its nonzero pixels, then interpolating on the zeroes using a
    shortest-path algorithm.