Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: HDF5 data set, unable to read contents Date: Fri, 11 Mar 2016 12:12:39 +0100 Organization: None Lines: 67 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 0hQZN9lUY9cRvOGEblspzgSlTyISppgczY9UM91atAlg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sys': 0.05; 'f.close()': 0.07; "'w')": 0.09; 'filename,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'references:': 0.09; 'subject:set': 0.09; 'python': 0.10; 'python.': 0.11; 'everyone,': 0.15; "'r')": 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'reproducing': 0.16; 'set:': 0.16; 'simplifies': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'element': 0.18; 'load': 0.20; 'extension': 0.20; 'arrays': 0.22; 'wrote': 0.23; 'elements': 0.23; 'import': 0.24; 'url:view': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'values': 0.28; 'cat': 0.29; "i'm": 0.30; 'print': 0.30; 'code': 0.30; 'maybe': 0.33; 'foo': 0.33; 'file': 0.34; 'this?': 0.34; 'so,': 0.35; 'could': 0.35; 'files,': 0.35; 'saved': 0.35; 'something': 0.35; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'creation': 0.38; 'mean': 0.38; 'data': 0.39; 'format': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'called': 0.40; 'some': 0.40; 'save': 0.60; 'your': 0.60; 'email addr:gmail.com': 0.62; 'skip:n 10': 0.62; 'matrix.': 0.84; 'subject:read': 0.84; 'url:drive': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd9af8.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104608 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 [[ [...] ]] $