2014-11-05 36 views

回答

1

下面是代碼joblib的關鍵部分,應該說明一些情況。

def _write_array(self, array, filename): 
    if not self.compress: 
     self.np.save(filename, array) 
     container = NDArrayWrapper(os.path.basename(filename), 
            type(array)) 
    else: 
     filename += '.z' 
     # Efficient compressed storage: 
     # The meta data is stored in the container, and the core 
     # numerics in a z-file 
     _, init_args, state = array.__reduce__() 
     # the last entry of 'state' is the data itself 
     zfile = open(filename, 'wb') 
     write_zfile(zfile, state[-1], 
          compress=self.compress) 
     zfile.close() 
     state = state[:-1] 
     container = ZNDArrayWrapper(os.path.basename(filename), 
             init_args, state) 
    return container, filename 

基本上,joblib.dump可以任選地與numpy.save壓縮陣列,它要麼存儲到磁盤,或(對於壓縮)存儲壓縮文件。此外,joblib.dump存儲NDArrayWrapper(或用於壓縮的ZNDArrayWrapper),它是一個輕量級對象,用於存儲包含數組內容的save/zip文件的名稱以及數組的子類。

相關問題