我是Python的新手,所以这个问题可能看起来很琐碎.但是,我没有找到类似的情况.我有一个20个节点的坐标矩阵.我想计算此集合中所有节点对之间的欧氏距离,并将它们存储在成对矩阵中.例如,如果我有20个节点,我希望最终结果是(20,20)的矩阵,每个节点对之间的欧几里德距离值.我尝试使用for循环遍历坐标集的每个元素并计算欧氏距离,如下所示:
ncoord=numpy.matrix('3225 318;2387 989;1228 2335;57 1569;2288 8138;3514 2350;7936 314;9888 4683;6901 1834;7515 8231;709 3701;1321 8881;2290 2350;5687 5034;760 9868;2378 7521;9025 5385;4819 5943;2917 9418;3928 9770')
n=20
c=numpy.zeros((n,n))
for i in range(0,n):
for j in range(i+1,n):
c[i][j]=math.sqrt((ncoord[i][0]-ncoord[j][0])**2+(ncoord[i][1]-ncoord[j][1])**2)
Run Code Online (Sandbox Code Playgroud)
但是,我收到的错误是"输入必须是方阵".我想知道是否有人知道这里发生了什么.谢谢
我使用"运行"按钮来运行我的整个代码.我还选择了整个代码并按下"运行此单元格"按钮并获得不同的结果.我正在使用"spyder"来编写我的代码.为什么会这样?
我想在 DEv C++ 5.9 中包含数组,但它给出了一个错误:
32 2 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\c++0x_warning.h [Error] #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
Run Code Online (Sandbox Code Playgroud)
这是因为我使用的 DEV-C++ 版本还是我的电脑 IOS?我使用了其他版本的 DEV C++,但由于我的计算机上装有 Windows 8,因此它们无法解决此问题,因此我需要使用此版本的 DEV C++。任何帮助表示赞赏。
谢谢