Pages

Showing posts with label np.savetxt. Show all posts
Showing posts with label np.savetxt. Show all posts

Using for loop to save outcome in in different file using np.savetxt

I wrote a script to do following task.

For each number that is created using range(0,100), I created xyz coordinates to generate guess structures for my calculations. The structure of the script is as follow.


for numPoints in range(0, 101):
     #do something to create x0, y0 and cons0 (xyz coordinates for a molecule)
     np.savetxt(fname_template.format(i=numPoints), np.c_[x0,y0,cons0],delimiter=' ',fmt='%10f')

This solved my problem.

I got this idea from following post in stack overflow.

fname_template = "Subarray.{i}.txt"
for i, sarr in enumerate(sub_arr):
    np.savetxt(fname_template.format(i=i), sarr, fmt='%s')
To create the file name I've used the new string formatting. Otherwise you can concatenate strings with + as "Subarray."+str(i)+".txt", but you have to make sure that all the elements that you concatenate are strings.

You may be interested in these posts

Error in image file conversion: convert-im6.q16: not authorized `test.eps' @ error/constitute.c/WriteImage/1037.

This error is because of the vulnerability. This allows remote execution of code using image formats. So, some Linux distributions by defaul...