開始使用免費開始

使用 h5py 匯入 HDF5 檔案

檔案 'LIGO_data.hdf5' 已經在你的工作目錄中。 在這個練習中,你會使用 h5py 函式庫將它匯入。 你也會印出它的資料型別,確認已正確匯入。 接著你會檢視檔案的結構,看看其中包含哪些 HDF 群組。

你可以在這裡找到 LIGO 資料與大量文件和教學資源。另有一份以此資料進行訊號處理的優質教學,連結在這裡

本練習屬於課程

Python 資料匯入入門

檢視課程

練習說明

  • 匯入套件 h5py
  • 將檔案名稱指定給變數 file
  • 以唯讀模式載入檔案到變數 data
  • 印出 data 的資料型別。
  • 列印 HDF5 檔案 'LIGO_data.hdf5' 中所有群組的名稱。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import packages
import numpy as np
import ____

# Assign filename: file


# Load file: data
data = h5py.File(____, ____)

# Print the datatype of the loaded file


# Print the keys of the file
for key in ____:
    print(____)
編輯並執行程式碼