I am reading points from a frequency spectrum graph into an array like this:
self.iq_fft = self.dofft(self.iq)#Gets values of all data point in block (in dB)
x = self.iq_fft #puts values into x for simplicity
maxi = max(x)
print maxi #This part works fine
def dofft(self, iq):
N = len(iq)
iq_fft = scipy.fftpack.fftshift(scipy.fft(iq))
Everything works great and it prints out the maximum value of the array to the screen perfect, however, when I try to save the max value to a file, like this:
savetxt('myfilelocation', maxi, fmt='%1.4f')#saves max(x) in binary format
It ends up saving the binary value to the text file and not the nice pretty ASCII one that printed to the screen. Funny thing is, when I just dump the whole array to a file it looks fine. Any ideas on how to fix this?
numpy.savetxt
saves an array to a file, and it looks like maxi
is a python Float. It's sort of unusual to use savetxt
to save a scalar (why not just use Python's built-in file i/o functions?), but if you must, this might work:
savetxt('myfilelocation', [maxi], fmt='%1.4f')
Notice that I've put maxi
in a list. Also, make sure that myfilelocation
doesn't end with a .gz
. If it does, numpy will compress it. When it doubt, just use .txt
, or no extension at all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.