当我运行这个小程序时,我在输出文件中输入了相同的3个值,但是如果我在每个for
周期中打印出值,我会得到所有不同的值。
为什么会发生这种情况?如何使其正确?
import random
import math
import numpy as np
def normalizeVector(_x, _y, _z):
_mag = math.sqrt(_x**2 + _y**2 + _z**2)
return _x/_mag, _y/_mag, _z/_mag
points2DL = []
pointsV = [0.] * 3
for _i in xrange(0, 10000):
_x = random.gauss(0, 1)
_y = random.gauss(0, 1)
_z = random.gauss(0, 1)
_nx, _ny, _nz = normalizeVector(_x, _y, _z)
_radius = 1.
_sx, _sy, _sz = _radius*_nx, _radius*_ny, _radius*_nz
pointsV[0] = _sx
pointsV[1] = _sy
pointsV[2] = _sz
points2DL.append(pointsV)
pointsA = np.array(points2DL, dtype=np.float32)
pointsA.tofile('sphere_points.csv', sep=",")