暂时通过这个案例解决了,样本数据还是差了点
https://stackoverflow.com/questions/66405264/generating-solid-spheres-in-python
我没实现,但是我有个建议,生成点的时候先生成一个二维的点,然后z坐标限制一下就行
感谢答复!但是你这种不太满足,我的指定空间是会变的; 你这种如果是简单的三维空间(正方体、圆柱体)勉强能用,但是样本效果很差,复杂的(锥体、球体)就没法了
我在网上找到了一个 demo, 但是通过可视化验证时, 发现数据并不好
def random_ball(num_points, dimension, radius=1):
from numpy import random, linalg
# First generate random directions by normalizing the length of a
# vector of random-normal values (these distribute evenly on ball).
random_directions = random.normal(size=(dimension,num_points))
random_directions /= linalg.norm(random_directions, axis=0)
# Second generate a random radius with probability proportional to
# the surface area of a ball with a given radius.
random_radii = random.random(num_points) ** (1/dimension)
# Return the list of random (direction & length) points.
return radius * (random_directions * random_radii).T
"""
array([[-0.23396152, -0.67936419, 0.55005001],
[ 0.1691557 , 0.03104764, -0.97471419],
[ 0.07458162, 0.61583175, 0.70946089],
[ 0.25455193, -0.55611147, -0.41187798],
[ 0.47061593, 0.24126442, -0.8053103 ],
[ 0.80211304, -0.10952756, 0.40626897],
[-0.21829698, -0.00210662, 0.2668299 ],
[-0.61603097, 0.06366497, -0.13768223],
[ 0.4580121 , -0.11881662, -0.44928392],
[-0.14152173, 0.0571525 , -0.51057342]])
"""
我感觉 numpy 之类的包,是有办法生成我想要的样本, 但是不知道咋写
两个需求其实是一个问题, 满足其一即可
– 韆 3年前