我需要生成2D
随机坐标并找到距一个中心位置的距离。
import numpy as np
import matplotlib.pyplot as plt
coords = np.random.random_integers(0,50,10)
print(coords)
要对坐标进行采样,您还可以分别对 x 和 y 坐标进行采样:
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randint(0, 50, 10)
y = np.random.randint(0, 50, 10)
plt.scatter(x, y)
plt.show()
上面的输出应该是包含 10 个采样点的散点图。接下来您可以确定所有点到定义的中心点的距离(x0, y0)
如下:
x0, y0 = 25, 25
d = np.sqrt((x0 - x)**2 + (y0 - y)**2)
print(d)
Where d
包含到中心点的距离和d[i]
是距离(x[i], y[i])
to (x0, y0)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)