Python: Issue reading in str from MATLAB .mat file using h5py and NumPy

Python: Issue reading in str from MATLAB .mat file using h5py and NumPy

I am having difficulty loading in 'str' variables 'Et' (Endtime) and 'St' (Starttime) from a MATLAB .mat file into Python.

I want identical output as in MATLAB. Instead I have had issues trying to solve this. See below for Python code and output.

# Import numpy and h5py to load in .mat files
import numpy as np
import h5py 

Load in Matlab ('-v7.3') data

fname = 'directory/file.mat' f = h5py.File(fname,'r')

create dictionary for data

data= {"average":np.array(f.get('average')),"median":np.array(f.get('median')),
"stdev":np.array(f.get('stdev')),"P10":np.array(f.get('p10')),
"P90":np.array(f.get('p90')),"St":np.str(f.get('stime')),
"Et":np.str(f.get('etime'))}

All other variables are arrays

print(data["Et"])

output:

<HDF5 dataset "etime": shape (1, 6), type "<u4">

I want to have a string in python equal to the string in MATLAB. In other words, I want print(data["Et"]) = '01011212000000' which is the date and time.

How can I solve this?

python string matlab numpy

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Python Strings Tutorial - How To Use Strings In Python

This Edureka video on 'Python Strings' will help you...

NumPy String Functions - String Operations in NumPy

NumPy library contains the numpy.char module for performing NumPy string functions. It consists of a set of vectorized string operations. The functions available are similar to the string operations in python. We perform these functions on arrays of string type

String methods in Python

String methods in Python - Python Strings

Python f-strings - The Ultimate Usage Guide

Python f-strings are the fastest string formatting option available on Python. It is robust, easy to read, concise and less prone to errors. If you are using Python 3.6+, you must switch to Python f-strings. In this detailed guide, we have covered...

NumPy Array Tutorial - Python NumPy Array Operations and Methods

Learn about NumPy Array, NumPy Array creation, various array functions, array indexing & Slicing, array operations, methods and dimensions,It also includes array splitting, reshaping, and joining of arrays. Even the other external libraries in Python relate to NumPy arrays.