I have this code in python for generating x, y, z positions in an unitary sphere. The problem is that in the output file they are not arranged in separate columns like x y z.
from numpy import random, cos, sin, sqrt, pi
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def rand_sphere(n):
z = 2 * random.rand(n) - 1 # uniform in -1, 1
t = 2 * pi * random.rand(n) # uniform in 0, 2*pi
x = sqrt(1 - z**2) * cos(t)
y = sqrt(1 - z**2) * sin(t)
return x, y, z
x, y, z = rand_sphere(200)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z)
plt.savefig('sphere.png')
#plt.show()
Outfile=open('output.txt','w')
Outfile.write('This line will be text\n')
Outfile.write('\n')
Outfile.write(repr(rand_sphere(200)))
Outfile.close()
The other problem is that before the x y z columns I need to repeat m=10 for each line;
Means that each line in the output file must be as following (without comma between them):
This line will be text
m x y z
20 ... ... ...
.
.
.
(200 lines)
So, I want to have three separate position columns plus one m=10 column.