Hi All: I am new to python and the question might be straightforward to some of you. My details question (writing in the steps of my task) is the following:
I need to generate 10 random 2D points under Gaussian distribution, which is easy:
Testing = np.random.multivariate_normal(mean, cov, 10)
where mean, cov are already defined.
I need to store the above values into a txt file, for later testing, which is also done:
with open("Testing.txt", "w") as f: f.write(str(Testing))
In step 3, I need to read all the 10 points created in step 1 which are stored in step 2 into a new list and do computation, which I wrote:
with open('Testing.txt') as f: Data = f.read()
note here the above two lines of codes are written in a separate script different from the script of step 1 & 2.
Step 3 itself seems OK, because if I test
print(Data)
it will print out in the terminal the same format as the values and format in the txt file, the problem is the data structure seems different from the Testing data structure created in step 1. For example if in Step 1, I add an additional line
plt.scatter(Testing[:,0],Testing[:,1],c='yellow')
it will plot the 10 points for me. But if I write the same command in the script of step 3
plt.scatter(Data[:,0],Data[:,1],c='yellow')
this will be an error "TypeError: string indices must be integers, not tuple". So apparently the structures for Data and Testing are different. Anyone can help me on this? Thanks!