I want to set the character length of each element of numpy array that is written in a text file
The output which I am getting currently is:
99941 1 56765 56767 51785 51793 0 0 0 0
101150 1 59006 59005 51782 51783 0 0 0 0
As you see in above case as the numbers increase the columns are shifted.
But in ideal case the output should look like:
99941 1 56765 56767 51785 51793 0 0 0 0
101150 1 59006 59005 51782 51783 0 0 0 0
Is there any way I can fix the character length of each element of numpy array so that it writes the elements from right to left after considering the element character length and keep the column formatting fixed?
This is the code snippet on which i am working.
def calculate(self, ElementNum1, ElementNum2):
Angle = Function().Transformation(ElementNum1, ElementNum2)
ElementInfo = Shell().getElement(ElementNum2)
Card1 = np.array([0,0,0,0,0,0,0,0,0,0])
Card1.itemset(0,(ElementInfo[0]))
Card1.itemset(1,(ElementInfo[1]))
Card1.itemset(2,(ElementInfo[2]))
Card1.itemset(3,(ElementInfo[3]))
Card1.itemset(4,(ElementInfo[4]))
Card1.itemset(5,(ElementInfo[5]))
return str(Card1)
def AngleSolution1(self,ElementPair):
Pair = np.genfromtxt(ElementPair, dtype=int, comments='None', delimiter=', ')
row = int(Pair.size/2)
p = mp.Pool(processes=4)
result = [p.apply_async(AngleCalculateFunction().calculate, args=(Pair[i][0], Pair[i][1])) for i in range(0, int(row/4))]
Result = open('Angles.csv', "a")
Result.write('\n'.join(map(str, ((((p.get()).replace('[','')).replace(']','')) for p in result))))
Result.write('\n')
Result.close()
p.close()
There are certain performance issues as I am using the multiprocessing incorrectly, but its out of the scope of this discussion.
fmtparameter innumpy.savetxtthat you can use for that.