file_path_a = "/Users/raj/jupyter-workspace/spark/a.txt"
...
afile = open(file_path_a, "w");
...
for i in range(10):
   a = np.random.random((3, 3))
...
alist = a[:a.shape[0]].T.flatten().tolist()
afile.write("%d,%d,%d:"%(i, a.shape[0], a.shape[1]))
afile.write(",".join(str(item) for item in alist))
afile.write("\n")
...