I got three random numbers and tried to display them in a format like "% .3f,% .3f,% .3f" in C language.
http://ideone.com/WGaHJR
import numpy as np
from numpy.random import *
pos = tuple( rand(3) )
frm = '%.3f, %.3f, %.3f'
print pos
print frm % tuple(pos)
result
(0.076222111784701618, 0.76602747950227201, 0.13864621611927097)
0.076, 0.766, 0.139
Reference http://stackoverflow.com/questions/7568627/using-python-string-formatting-with-lists
v0.2
Change the coordinate value to the range [-1,1].
http://ideone.com/PZPfxe
import numpy as np
from numpy.random import *
for loop in range(15):
pos = tuple( rand(3) * 2 - 1 )
frm = '[ %.3f, %.3f, %.3f ],'
# print pos
print frm % tuple(pos)
(Addition) @ Shiracamus's comment is better than the above.
Recommended Posts