0

I tried to open a .bin file with np.fromfile. However, I am not sure what is the right way to load the file correctly. Here is the code that produced this .bin file. Thanks!

def write_bin(file_path,data_np): #data_np is a float32 array with shape (1, 64, 1)
    file_path   = file_path + '.bin'
    dim_np      = np.array((data_np.shape),dtype=np.int32)  
    dim_num     = np.int32(len(dim_np)) 
    
    output_file = open(file_path, 'wb') 
    output_file.write(dim_num) # write dim_num (np.int32)
    output_file.write(np.array(dim_np)) # write dim_np  (np.int32)
    output_file.write((data_np)) # write array (np.float32)
    output_file.close()
    return
xxxnxxxnn
  • 23
  • 4
  • https://stackoverflow.com/questions/1035340/reading-binary-file-and-looping-over-each-byte – bigbounty Jul 13 '20 at 08:13
  • If you just write the data for each array to the file with no additional information, when you open the file again, how are you hoping to determine where one array's data ends and the next begins? How are you hoping to know what the array sizes should be? – Karl Knechtel Jul 13 '20 at 08:14
  • Actually this is a part of someone else's code which I am trying to understand. According to what I understood from the author's code, data_np has an array of shape (1, 64, 1). With this information, would it be possible to open the .bin properly? – xxxnxxxnn Jul 13 '20 at 08:40

0 Answers0