I believe the input file is a binary file, with only 32-bit unsigned integers. (I am new to Matlab so don't be cross with me if I am wrong.)
There are several ways to store the data. I would advise to create a 3-dimensional dictionary. But one can argue about that. Perhaps creating a class for storing the data is even more elegant.
As far as I understand your Matlab code I believe you could write it in this way in Python.
I hope I understood your problem right.
There are several ways to store the data. I would advise to create a 3-dimensional dictionary. But one can argue about that. Perhaps creating a class for storing the data is even more elegant.
As far as I understand your Matlab code I believe you could write it in this way in Python.
import struct # for reading binary data files = ['C:\temp\day1.dat','C:\temp\day2.dat']; # Files to read (1 file for each day apple pickers worked) filedata = {} # prepare empty dictionary for filedata for file in files: # Loop over each file filedata[file] = {} # Create new dict for this file fid = open(file,'rb') # Open for reading binary data numShifts = struct.unpack('i', fid.read(4)) # Read # of worker shifts on that day for shift in range(1, numShifts): # Now loop over the shifts filedata[file][shift] = {} # Create new dict for this shift numFarmers = struct.unpack('i', fid.read(4)) # Read number of farmers working that shift for farmer in range(1, numFarmers): # Now read number of apples picked by each farmer on that shift. filedata[file][shift][farmer] = struct.unpack('i', fid.read(4)) close(fid)I have no data to test it so there may be errors in it. In this case the numShifts and numFarmers are not stored in the 3-D dictionary but I believe you only need them in the process.
I hope I understood your problem right.