- Hands-On Artificial Intelligence for IoT
- Amita Kapoor
- 121字
- 2021-07-02 14:02:01
Using HDF5 with PyTables
Let's first create an HDF5 file from the numeric data we have in the temp.csv file with the following steps:
- Get the numeric data:
import numpy as np
arr = np.loadtxt('temp.csv', skiprows=1, usecols=(2,3), delimiter=',')
- Open the HDF5 file:
import tables
h5filename = 'pytable_demo.hdf5'
with tables.open_file(h5filename,mode='w') as h5file:
- Get the root node:
root = h5file.root
- Create a group with create_group() or a dataset with create_array(), and repeat this until all the data is stored:
h5file.create_array(root,'global_power',arr)
- Close the file:
h5file.close()
Let's read the file and print the dataset to make sure it is properly written:
with tables.open_file(h5filename,mode='r') as h5file:
root = h5file.root
for node in h5file.root:
ds = node.read()
print(type(ds),ds.shape)
print(ds)
We get the NumPy array back.
推薦閱讀
- Dreamweaver CS3 Ajax網(wǎng)頁設(shè)計入門與實例詳解
- Go Machine Learning Projects
- PyTorch深度學(xué)習(xí)實戰(zhàn)
- 人工智能實踐錄
- Grome Terrain Modeling with Ogre3D,UDK,and Unity3D
- 分?jǐn)?shù)階系統(tǒng)分析與控制研究
- 網(wǎng)中之我:何明升網(wǎng)絡(luò)社會論稿
- 基于神經(jīng)網(wǎng)絡(luò)的監(jiān)督和半監(jiān)督學(xué)習(xí)方法與遙感圖像智能解譯
- 從零開始學(xué)Java Web開發(fā)
- Hands-On SAS for Data Analysis
- 數(shù)據(jù)要素:全球經(jīng)濟(jì)社會發(fā)展的新動力
- Oracle 11g Anti-hacker's Cookbook
- WPF專業(yè)編程指南
- 輸送技術(shù)、設(shè)備與工業(yè)應(yīng)用
- 這樣用Word!