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.

reBourne
  • 127
  • 1
  • 1
  • 9

2 Answers2

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

Community
  • 1
  • 1
Ricardo Cárdenes
  • 8,245
  • 1
  • 19
  • 32
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

Community
  • 1
  • 1
Sam Inverso
  • 371
  • 2
  • 7