小编Mec*_*ian的帖子

数据集中两点之间的最大距离并识别这些点

我有一个由几个点的 x,y,z 坐标组成的矩阵。我想找到极值点,即相距最远的两点。

我可以在 matlab 中找到一种方法,但我需要在 Python 中使用它

这是matlab中的代码

A = randint(500,3,[-5 5]);
D=pdist(A);
D=squareform(D);
[N,I]=max(D(:));
[I_row, I_col] = ind2sub(size(D),I);
Run Code Online (Sandbox Code Playgroud)

pdist 给出点对(i,j)之间的距离。squareform 给出矩阵输出 在最后两个步骤中,我尝试找到矩阵 I_row、I_col 的索引。

点 I_row 和 I_col 具有最大距离..

任何人都可以建议我在 python 中使用一种有效的方法,因为我所有的其他代码都在 python 中。

python algorithm matlab numpy

6
推荐指数
2
解决办法
8781
查看次数

如何在 matplotlib 标题中包含符号

我想在 matplotlib 标题中包含符号,但以下代码不起作用。

import matplotlib.pyplot as plt
import numpy as np

N_combs=10
t1 = np.random.randint(100, size=(N_combs,2))
g1=np.random.randint(100, size=(N_combs,2))
plt.plot(range(100), np.random.randn(100, N_combs))    
plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])
Run Code Online (Sandbox Code Playgroud)

错误:

  File "<ipython-input-972-589f95b4b1cf>", line 8, in <module>
    plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])

  File "<ipython-input-972-589f95b4b1cf>", line 8, in <listcomp>
    plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])

TypeError: cannot unpack non-iterable …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

1
推荐指数
1
解决办法
3917
查看次数

标签 统计

python ×2

algorithm ×1

matlab ×1

matplotlib ×1

numpy ×1