HDF stands for Hierarchical Data Format, a well known file format for storing and organizing large amounts of numerical data . In python HDF5 data files can be handled by means of the h5py module. This article explains how to read and write hdf5 files in Python. See also h5py quick start, How to access HDF5 data from Python, and Read HDF 5 file in Python
See a quick example in post #2 below.
-
- Active Topics
-
-
- by Eli 22 hours ago Re: What is in Your Mind? View the latest post Replies 703 Views 299999
- by Eli 22 hours ago Russia Invades Ukraine View the latest post Replies 663 Views 235180
- by Eli 2 days ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 326 Views 34195
- by Eli 3 days ago PySpark for Large Data Processing View the latest post Replies 1 Views 6866
- by Eli 1 week ago President Museveni's Speech During International Development Association (IDA) Summit View the latest post Replies 1 Views 280
- by Eli 1 week ago From Simple Linear Regression Analysis to Covariance & Correlation to Independent Determinant, and R-Squared View the latest post Replies 11 Views 24839
- by Eli 1 week ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 34 Views 67384
- by Eli 1 week ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 34 Views 58081
- by Eli 1 week ago Programmatically Manipulate Files: Renaming, Reading, Writing, Deleting, and Moving Files Between Folders View the latest post Replies 7 Views 15772
- by Eli 2 weeks ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 17797
-
How to Read and Write HDF5 Data file in Python
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Here is a quick example on how to create, save and read data into and from hdf5 files in Python (See more examples here).
- import numpy as np
- import h5py
- #Create data files, here we create two random matrices
- data_file1 = np.random.random(size = (1000, 1000))
- data_file2 = np.random.random(size = (500, 400))
- #Save data files in the hdf5 format in the file hdf5_data
- with h5py.File('/home/tssfl/Desktop/hdf5_data.h5', 'w') as hdf:
- hdf.create_dataset("data_set1", data = data_file1)
- hdf.create_dataset("data_set2", data = data_file2)
- #Read the dataset:
- f = h5py.File('/home/tssfl/Desktop/hdf5_data.h5', 'r')
- #Check the dataset keys
- f.keys()
- Out[3]: [u'data_set1', u'data_set2']
- #Get specific data files
- data1 = f['data_set1']
- #Check data shape
- data1.shape
- Out[5]: (1000, 1000)
- #Similarly for data_set2
- data2 = f['data_set2']
- data2.shape
- Out[7]: (500, 400)
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
-
- Similar Topics
- Replies
- Views
- Last post
-
- Information
-
Who is online
Users browsing this forum: No registered users and 5 guests