Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104534 > unrolled thread

HDF5 data set, unable to read contents

Started byvarun7rs@gmail.com
First post2016-03-10 08:50 -0800
Last post2016-03-11 12:12 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  HDF5 data set, unable to read contents varun7rs@gmail.com - 2016-03-10 08:50 -0800
    Re: HDF5 data set, unable to read contents dieter <dieter@handshake.de> - 2016-03-11 10:37 +0100
    Re: HDF5 data set, unable to read contents Peter Otten <__peter__@web.de> - 2016-03-11 12:12 +0100

#104534 — HDF5 data set, unable to read contents

Fromvarun7rs@gmail.com
Date2016-03-10 08:50 -0800
SubjectHDF5 data set, unable to read contents
Message-ID<f8787852-6566-4ed5-a969-262372be243e@googlegroups.com>
Hello everyone,

I recently came across a package called matrix2latex which simplifies the creation of very large tables. So, I saved my data in .mat format using the '-v7.3' extension so that they can be read by python.

Now, when I try to read these files, I'm having some problems in reproducing the whole matrix. Whenever I try and print out an element of the array, I only get 'HDF5 object reference' as the output. This is basically the short code I wrote and what I basically want to do is have the values of the elements in the arrays and not the 'HDF5 object reference' thing. ex [ [ 1 2 3 4 ], [2 3 4 5 ]...]

Could you please help me with this? The link to the .mat file is as below

https://drive.google.com/file/d/0B2-j91i19ey2Nm1CbVpCQVdZc3M/view?usp=sharing


import numpy as np, h5py
from matrix2latex import matrix2latex

f = h5py.File('nominal_case_unfix.mat', 'r')
data = f.get('nominal_case_unfix')
np_data = np.array(data)
print np_data



Thank You

[toc] | [next] | [standalone]


#104604

Fromdieter <dieter@handshake.de>
Date2016-03-11 10:37 +0100
Message-ID<mailman.12.1457689071.26429.python-list@python.org>
In reply to#104534
varun7rs@gmail.com writes:

> I recently came across a package called matrix2latex which simplifies the creation of very large tables. So, I saved my data in .mat format using the '-v7.3' extension so that they can be read by python.
>
> Now, when I try to read these files, I'm having some problems in reproducing the whole matrix. Whenever I try and print out an element of the array, I only get 'HDF5 object reference' as the output.

"print" implicitely converts an object to a string.
As there are a huge number of potential object types, "print" itself
cannot know all the relevant details regarding string convertion for
all types -- each individual type must help (by defining
"__str__" and/or "__repr__"). If it does not help, you
get a printout as the above.

In an interactive Python session, you can use "help(...)" on
one of those "HDF5 object reference"s. This will show you the
API of the object - i.e. how to interact with the object
(such as accessing/modifying the contained information).
"vars(...)" may also help (it shows the object's (instance) attributes).

[toc] | [prev] | [next] | [standalone]


#104608

FromPeter Otten <__peter__@web.de>
Date2016-03-11 12:12 +0100
Message-ID<mailman.15.1457694774.26429.python-list@python.org>
In reply to#104534
varun7rs@gmail.com wrote:

> Hello everyone,
> 
> I recently came across a package called matrix2latex which simplifies the
> creation of very large tables. So, I saved my data in .mat format using
> the '-v7.3' extension so that they can be read by python.
> 
> Now, when I try to read these files, I'm having some problems in
> reproducing the whole matrix. Whenever I try and print out an element of
> the array, I only get 'HDF5 object reference' as the output. This is
> basically the short code I wrote and what I basically want to do is have
> the values of the elements in the arrays and not the 'HDF5 object
> reference' thing. ex [ [ 1 2 3 4 ], [2 3 4 5 ]...]
> 
> Could you please help me with this? The link to the .mat file is as below
> 
> https://drive.google.com/file/d/0B2-j91i19ey2Nm1CbVpCQVdZc3M/view?usp=sharing
> 
> 
> import numpy as np, h5py
> from matrix2latex import matrix2latex
> 
> f = h5py.File('nominal_case_unfix.mat', 'r')
> data = f.get('nominal_case_unfix')

Did you mean _fix instead of _unfix?

> np_data = np.array(data)
> print np_data

Maybe it has something to do with the way you saved your data? When I save 
and load a matrix I don't see those object references:

$ cat h5write.py
import numpy as np
import h5py

a = np.array([[1,2,3], [4,5,6]])

f = h5py.File('save.mat', 'w')
d = f.create_dataset("foo", data=a)
f.close()
$ python h5write.py
$ cat h5read.py
import sys
import numpy as np
import h5py

filename, matrixlocation = sys.argv[1:]

f = h5py.File(filename, 'r')
d = f.get(matrixlocation)
print np.array(d)
$ python h5read.py save.mat foo
[[1 2 3]
 [4 5 6]]

However, with your data set:

$ python h5read.py nominal_case_fix.mat nominal_case_fix
[[<HDF5 object reference> <HDF5 object reference> <HDF5 object reference>
[...]
  <HDF5 object reference> <HDF5 object reference> <HDF5 object reference>]]
$

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web