我有一个 float 列表,表示点的 x 和 y 坐标。
(-379.99418604651157, 47.517234218543351, 0.0) #representing point x
一条边包含两个这样的数字。
我想使用图形遍历算法,例如 dijkstra,但使用 float (例如上述算法)没有帮助。 我实际上正在寻找的是一种近似这些数字的方法:
(-37*.*, 4*.*, 0.0)
是否有一个 python 函数可以做到这一点?
最佳答案
“...使用上面的 float 没有帮助...” - 为什么不呢?我不记得整数是 Dijkstra 的要求。你不关心边缘的长度吗?这更有可能是 float ,即使端点以整数值表示。
我引用了 Steve Skiena 的“算法设计手册”:
Dijkstra's algorithm proceeds in a series of rounds, where each round establishes the shortest path from s to some new vertex. Specifically, x is the vertex that minimizes dist(s, vi) + w(vi, x) over all unfinished 1 <= i <= n...
距离 - 没有提到整数。
关于python - python中的数字近似,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4626370/