在 Python 中查看 .mat 的结构
本练习将带您查看之前载入的 MATLAB 字典中包含了什么内容。
文件 'albeck_gene_expression.mat' 已载入到变量 mat 中。下列库也已按如下方式导入:
import scipy.io
import matplotlib.pyplot as plt
import numpy as np
该文件同样包含来自 UCDavis Albeck 实验室的基因表达数据。
本练习是课程的一部分
Python 数据导入入门
练习说明
- 对字典
mat使用.keys()方法并打印其键。大多数键(实际上,凡是不以 '__' 开头和结尾的键)都是对应 MATLAB 环境中的变量。 - 打印
mat中键'CYratioCyt'所对应值的类型。回忆:mat['CYratioCyt']即可访问该值。 - 使用
numpy的shape()函数打印键'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()