Ufunc 'add' did not contain a loop with the signature matching type dtype ('S32') ('S32') ('S32')

I am trying to run someone script for some simulations that I did to try to build some histograms, but when I do this, I always get the error message mentioned above. I have no idea what happened.

Here is the complete trace error:

File "AVAnalyse.py", line 205, in <module> 
  f.write(line[0]+'  '+line[1]+'  '+line[2]+'  '+line[3]) 
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S32') dtype('S32') dtype('S32')

This is the code I'm trying to run:

name_out = "histogram_"+donor+"_"+acceptor+".dat"   
  f = open(name_out,'w')
  f.write('distance  d.probability  efficiency  e.probability')
  for line in dist_hist:
    f.write(line[0]+'  '+line[1]+'  '+line[2]+'  '+line[3])
  f.close()


  print "data saved in " +"histogram_"+donor+"_"+acceptor+".dat"

Any help / explanation that I'm wrong will be greatly appreciated! Thank you in advance!

+4
source share
1 answer

, line[0], line[1], line[2], line[3] dist_hist. dict_hist numpy.ndarray. dict_hist (, np.float64) ( ). : np.float64 str. TypeError, line[0], line[1], line[2], line[3] str.

:

name_out = "histogram_"+donor+"_"+acceptor+".dat"   
f = open(name_out,'w')
f.write('distance  d.probability  efficiency  e.probability')
for line in dist_hist:
  f.write(str(line[0])+'  '+str(line[1])+'  '+str(line[2])+'  '+str(line[3]))
f.close()

print "data saved in " +"histogram_"+donor+"_"+acceptor+".dat"

EDIT:

:

name_out = "histogram_"+donor+"_"+acceptor+".dat"   
f = open(name_out,'w')
f.write('distance  d.probability  efficiency  e.probability')
for line in dist_hist:
  f.write(line[0]+'  '+line[1]+'  '+line[2]+'  '+line[3])
f.close()

:

name_out = "histogram_" + donor + "_" + acceptor + ".dat"   
f = open(name_out,'w')
f.write('distance  d.probability  efficiency  e.probability\n')
for line in dist_hist:
  f.write(str(line[0]) + '  ' + str(line[1]) + '  ' + str(line[2]) + '  ' + str(line[3]) + '\n')
f.close()

. - , 2- ( ).

+8

Source: https://habr.com/ru/post/1667805/


All Articles