I have some code that goes through several iterations. At each iteration, the code generates a numpy based array. I am adding a numpy based array to an existing binary .dat file. To generate data, I use the following code:
WholeData = numpy.concatenate((Location,Data),axis=0) # Location & Data are two numpy arrays DataBinary = open('DataBinary.dat','ab') WholeData.tofile(DataBinary) DataBinary.close()
I am trying to read the entire binary file into an array. I have the following difficulties:
I tried the following code:
NewData = numpy.array('f') File1 = open('DataBinary.dat','rb') NewData.fromstring(File1.read()) File1.close()
Error Status:
Traceback (last last call): File "", line 1, in AttributeError: object 'numpy.ndarray' does not have the attribute 'fromstring'
I tried using an array based array and then read the file in the array.
from array import array File1 = open('DataBinary.dat','rb') NewData.fromstring(File1.read()) File1.close()
However, NewData is erroneous, i.e. he is not like WholeData . I think storing data as numpy.array and reading it as array.array may not be a very good option.
Any suggestion would be appreciated.
source share