0

我使用此代码生成 xyz 坐标。

from random import *

uniqcoord = [7.63, 28.05, 66.36]         # my file contains 100 such list of points

for i in range(10):
    i = i + 1
    x,y,z = uniqcoord
    x1,y1,z1 = (uniform(x[0]-3.5,x[0]+3.5), uniform(y[1]-3.5,y[1]+3.5), uniform(z[2]-3.5,z[2]+3.5))
    print i, '\t', x1,y1,z1

当我运行这个程序时,它显示错误。
当我用孔号运行这个程序时,它可以工作。
怎么解决???

4

2 回答 2

3

你的x, y,zfloat, 不是list. 所以你不能有x[0]等等。你会得到一个no attributetypeerror

于 2013-09-13T16:37:38.113 回答
1

您在该x1,y1,z1行中错误地使用了 x,y,z。看看我在下面做了什么;

from random import *

uniqcoord = [7.63, 28.05, 66.36]         # my file contains 100 such list of points

for i in range(10):
    i=i+1
    x,y,z = uniqcoord
    x1,y1,z1 = (uniform(uniqcoord[0]-3.5,uniqcoord[0]+3.5), uniform(uniqcoord[1]-3.5,uniqcoord[1]+3.5), uniform(uniqcoord[2]-3.5,uniqcoord[2]+3.5))
    print i, '\t', x1,y1,z1

x[0] 不存在,但是 uniqcoord[0] = x 因为 uniqcoord = [x,y,z] 等等。

结果:

1   5.86941266341 29.4004245806 67.1323961576
2   6.38143060206 29.7045813689 69.4867869245
3   5.55280335095 29.9472835241 63.7388152633
4   10.5607637875 26.6269381673 69.5256503601
5   7.29826364813 28.5740308696 65.2122276564
6   8.24134391937 30.880058802 69.8445734597
7   10.246919304 27.9240839326 64.9480054046
8   8.26957559527 28.5700768795 63.996117793
9   5.88677020227 30.0621250245 63.7431176092
10  8.98100830174 27.3378753286 63.1329446911

这就是你要找的。

于 2013-09-13T16:40:34.150 回答