给定五个现有向量,如何找到一个新的等距向量?

How to find a new equidistant vector, given five existing vectors?

我有向量 v1、v2、v3、v4、v5,暗淡度为 100,我需要找到一个中心向量,它们与每个向量的距离相等。

更新:从数学上看this answer,有没有办法实现Numpy/Python中的解法?

一切都取决于向量在 Python 中的呈现方式。

让 v1、v2、...、v5 显示为值列表。每个列表都有 len = 100.

在这种情况下,我会执行以下操作:

np.vstack([v1, v2, v3, v4, v5]).mean(axis=1)

如果向量已经组成 5x100 数组,例如arr, arr.shape=(5, 100), 您可以通过以下方式获得解决方案:

arr.mean(axis=1)

编辑:[问题是 changed/clarified]

要获得等距向量 (x),请查看我刚刚编写的以下代码片段:

import numpy as np
from scipy.optimize import least_squares

np.random.seed(10)
vector_as_rows = np.random.rand(5, 100)

def Q(x, vs=vector_as_rows):
    d = x[-1]
    result = list()
    for v in vs:
        result.append(np.linalg.norm(v-x[:-1])- d)
    result.append(0)
    return result

res = least_squares(Q, np.random.rand(101)).x

for v in vector_as_rows:
    print("Dist between x and v[k]: ", np.linalg.norm(v - res[:-1]))

因此,res[:-1] (len = 100) 与所有 v[i] 等距; res[-1]是距离值。

Dist between x and v[k]:  2.530871535402036
Dist between x and v[k]:  2.530871505069009
Dist between x and v[k]:  2.530871545163243
Dist between x and v[k]:  2.5308715299141045
Dist between x and v[k]:  2.5308715309178402

我怀疑这个问题有解析解;我刚刚实施 解决未定线性系统的可能方法之一 您提供的link。

A = (vector_as_rows[0] - vector_as_rows[1:]) * 2
res = np.dot(np.linalg.pinv(A), (vector_as_rows[0]**2 - vector_as_rows[1:]**2).sum(axis=1))
for v in vector_as_rows:
    print("Dist between x and v[k]: ", np.linalg.norm(v - res))

结果是:

Dist between x and v[k]:  5.569005123058085
Dist between x and v[k]:  5.569005123058085
Dist between x and v[k]:  5.569005123058084
Dist between x and v[k]:  5.569005123058084
Dist between x and v[k]:  5.569005123058085

我用的是np.linalg.pinv,就是Moore-Penrose伪反演。使用它,我得到了未定线性系统的最小长度解。因此,获得的向量 res 具有该问题所有可能解的最小范数。