reBourne
reBourne

Reputation: 127

How to read matlab array in python using h5py

i have a matlab array > 2GB ... i want to read it using h5py. The data is a simple 3D double array. But i simply couldn't find a clue on the internet.

Can someone help me ? I just need an example, how it's done. The h5py documentation couldn't help me.

Upvotes: 3

Views: 23144

Answers (2)

Sam Inverso
Sam Inverso

Reputation: 441

An alternative using dictionary syntax:

import h5py
f = h5py.File('somefile.mat','r')
myvar = f['myvar'].value

To load all values look at: https://stackoverflow.com/a/29856030/1615523

Upvotes: 3

Ricardo Cárdenes
Ricardo Cárdenes

Reputation: 9172

This question has been answered before, but refering to .mat files. As @vikrantt said here -I'm copying his example code,- recent versions of Matlab save to HDF5 format and those you can just:

import numpy as np, h5py 
f = h5py.File('somefile.mat','r') 
data = f.get('data/variable1') # Get a certain dataset
data = np.array(data)

Note that this is covered in h5py's own documentation about it's high level API. I'd recommend reading Group Objects to understand better how to extract information from the file, and then Numpy Compatibility

Upvotes: 3

Related Questions