Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104608
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: HDF5 data set, unable to read contents |
| Date | 2016-03-11 12:12 +0100 |
| Organization | None |
| Message-ID | <mailman.15.1457694774.26429.python-list@python.org> (permalink) |
| References | <f8787852-6566-4ed5-a969-262372be243e@googlegroups.com> |
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>]]
$
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web