Python 生成随机点坐标
答案:1 悬赏:20 手机版
解决时间 2021-11-23 01:18
- 提问者网友:战皆罪
- 2021-11-22 03:37
Python 生成随机点坐标
最佳答案
- 五星知识达人网友:罪歌
- 2021-11-22 03:45
import random
import numpy as np
List = np.array([(0,0),(1,1),(1.6,1.8),(3,3)])
d = 0.5
def get_random(low,high):
return((high-low)*random.random()+low)
n = 0
while n<100000:
x = get_random(0,3)
y = get_random(0,3)
rand_tuple = np.array([x,y])
tmp_dist = np.sqrt(np.sum(np.square(List-rand_tuple),axis = 1))
tmp_dist_bool = tmp_dist >= d
if np.sum(tmp_dist_bool) == len(List):
print(x,y)
break
n += 1
if n==100000:
print("After",n,"tries,can't get a random point!Check whether the problem has a solution!")
import numpy as np
List = np.array([(0,0),(1,1),(1.6,1.8),(3,3)])
d = 0.5
def get_random(low,high):
return((high-low)*random.random()+low)
n = 0
while n<100000:
x = get_random(0,3)
y = get_random(0,3)
rand_tuple = np.array([x,y])
tmp_dist = np.sqrt(np.sum(np.square(List-rand_tuple),axis = 1))
tmp_dist_bool = tmp_dist >= d
if np.sum(tmp_dist_bool) == len(List):
print(x,y)
break
n += 1
if n==100000:
print("After",n,"tries,can't get a random point!Check whether the problem has a solution!")
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯