python读mat转成矩阵,使用h5py打开Mat文件并将数据转换为numpy矩阵

本文介绍了如何使用h5py库将包含矩阵的MAT文件转换为numpy数组。在尝试将数据加载到numpy数组时,遇到了将HDF5对象引用转换为其值的问题。解决方案涉及到对dtype=object类型的数组进行额外的索引操作,特别是当这些数组是0维时,需要用空元组(())来获取其内容。
摘要由CSDN通过智能技术生成

I have a mat file which contains 2 different cells containing matrices of different size. I need to convert that data into a numpy array using h5py for an experiment (I'm new in h5py. I thought it was as easy as it is explained here

Reading the file works well, putting the data in the numpy array also works well, but I need the value representation of each position inside each matrix inside each cell, taking into account that when I print for example np.array(x[0][1]), I receive just the reference to the array(< HDF5 object reference>, dtype=object) and I need the values inside it...

It looks very tempting to convert the cell into a 3d matrix in matlab, however I don't count with root permissions to do anything in Matlab other than reading data and doing calculations (no saving anything).

If someone has already worked on this, or someone has any idea about how t

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值