3

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.

4
  • 2
    Someone answered here (see second answer) Commented Jan 31, 2014 at 12:51
  • But it doesn't work for me : print data results to 'None' Commented Jan 31, 2014 at 12:57
  • Ok, got it. I didn't use option 'r' and overwrote the file with nothing :S Now it works ! Thanks ! Commented Jan 31, 2014 at 13:06
  • I'll answer anyway, as the other question specifies ".mat" files Commented Jan 31, 2014 at 13:18

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.