開始使用免費開始

在 Python 中查看 .mat 的結構

在這裡,你要探索上一個練習中載入的 MATLAB 字典裡有哪些內容。

檔案 'albeck_gene_expression.mat' 已載入到變數 mat。下列函式庫也已匯入:

import scipy.io
import matplotlib.pyplot as plt
import numpy as np

這個檔案同樣包含 UCDavis 的 Albeck Lab 所產生的基因表現資料。

本練習屬於課程

Python 資料匯入入門

檢視課程

練習說明

  • 對字典 mat 使用 .keys() 方法並印出所有鍵。大多數的鍵(事實上,不是以 '__' 開頭且結尾的那些)對應到原本 MATLAB 環境中的變數。
  • 印出在 mat 中鍵 'CYratioCyt' 所對應值的型別。回想 mat['CYratioCyt'] 可存取該值。
  • 使用 numpyshape() 函式,印出鍵 'CYratioCyt' 所對應值的形狀。
  • 執行整個指令稿,看看帶有震盪模式的基因表現資料!

動手互動練習

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

# Print the keys of the MATLAB dictionary
print(____)

# Print the type of the value corresponding to the key 'CYratioCyt'


# Print the shape of the value corresponding to the key 'CYratioCyt'


# Subset the array and plot it
data = mat['CYratioCyt'][25, 5:]
fig = plt.figure()
plt.plot(data)
plt.xlabel('time (min.)')
plt.ylabel('normalized fluorescence (measure of expression)')
plt.show()
編輯並執行程式碼