書名: 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.
推薦閱讀
- 基于C語言的程序設計
- Mastering Hadoop 3
- 計算機圖形學
- PowerShell 3.0 Advanced Administration Handbook
- Python Artificial Intelligence Projects for Beginners
- PyTorch深度學習實戰
- CompTIA Linux+ Certification Guide
- 步步圖解自動化綜合技能
- 網絡服務搭建、配置與管理大全(Linux版)
- Deep Learning Essentials
- 工業機器人基礎
- Learning OpenShift
- 歐姆龍CP1系列PLC原理與應用
- 從實踐中學嵌入式Linux操作系統
- 單片機技術