![](/img/trans.png)
[英]How do I add values in parallel to an existing HDF5 file with 3 groups and 12 datasets in each group using h5py?
[英]How do I keep an h5py group in memory after closing the file?
關閉文件后如何將 h5py 組保留在內存中?
在以下代碼之后:
import h5py
feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"]
我可以訪問worm_features
因為它是一個h5py 組( <HDF5 group "/worm" (4 members)>
)
但是在我運行這條線之后:
feature_file.close()
我無法再訪問worm_features
。 它現在顯示為<Closed HDF5 group>
。
因為我需要為大約 20 個文件加載 worm_features h5py 組,所以我想在處理我加載到內存中的數據之前關閉這些文件。 這不可能嗎?
使用 .value 從數據集中提取所需的變量。
例子:
import h5py
feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"].value
feature_file.close()
print worm_features
使用[:]
將數據集的值復制到變量中,以便在關閉 hdf5 文件后訪問數據集。
import h5py
feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"] [:]
feature_file.close()
print (worm_features)
.value
對我不起作用並引發以下錯誤:
AttributeError: 'Dataset' object has no attribute 'value'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.