Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 求矩阵中每个点之间的距离_Arrays_Python 3.x_Matrix_Multidimensional Array - Fatal编程技术网

Arrays 求矩阵中每个点之间的距离

Arrays 求矩阵中每个点之间的距离,arrays,python-3.x,matrix,multidimensional-array,Arrays,Python 3.x,Matrix,Multidimensional Array,您好,如何计算矩阵中每个点与特定点(如[1,3](点0)或[4,7](点1)或[7,2](点2))之间的距离,并更改该特定值以显示最接近该特定坐标的点 def create_zero_matrix(n,m): return [[0 for i in range(m)] for j in range(n)] def m_tight_print(m): for i in range(len(m)): line = '' for j in range(

您好,如何计算矩阵中每个点与特定点(如[1,3](点0)或[4,7](点1)或[7,2](点2))之间的距离,并更改该特定值以显示最接近该特定坐标的点

def create_zero_matrix(n,m):
    return [[0 for i in range(m)] for j in range(n)]

def m_tight_print(m):
    for i in range(len(m)):
        line = ''
        for j in range(len(m[0])):
            line += str(m[i][j])
        print(line)


def pd_map(r,c,sites):
    blank = create_zero_matrix(r,c)
    for count, site in enumerate(sites):
        blank[site[0]][site[1]] = count #locating the shops


以上是测试用例,但我只能从我的代码中得到

>>> pprint(pizzaMap)
[[0, 0, 0, 0, 0, 0, 0, 'X', 1, 1]
 [0, 0, 0, 0, 0, 0, 0, 1, 1, 1]
 [0, 0, 0, 0, 0, 0, 0, 1, 1, 1]
 [0, 0, 0, 0, 0, 0, 'X', 1, 1, 1]
 ['X', 0, 0, 0, 0, 0, 1, 1, 1, 1]
 [2, 2, 2, 2, 2, 'X', 1, 1, 1, 1]
 [2, 2, 2, 2, 2, 2, 1, 1, 1, 1]
 [2, 2, 2, 2, 2, 2, 2, 1, 1, 1]
 [2, 2, 2, 2, 2, 2, 2, 1, 1, 1]
 [2, 2, 2, 2, 2, 2, 2, 'X', 1, 1]]

这看起来像是一个可疑的家庭作业任务。此外,除非您指定“距离”的含义,否则无法解决您的任务。有几种距离度量,你指的是哪一种?另外,我认为你在这里误用了“矩阵”这个术语。是的,您将其存储在2D数组中,但这并不能使其成为矩阵数学意义上的“矩阵”。您试图在这里完成的工作称为“沃罗诺图”。()
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 2, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
```.
I tried to use numpy.argwhere() but in the end I could not do it. What code must I use such that I am able to get my test case?