Home Python equivalent of array of structs from MATLAB
Reply: 0

Python equivalent of array of structs from MATLAB

user1633 Published in May 27, 2018, 3:35 am

I am familiar with the struct construct from MATLAB, specifically array of structs. I am trying to do that with dictionary in Python. Say I have a initialized a dictionary:

samples = {"Name":"", "Group":"", "Timeseries":[],"GeneratedFeature":[]}

and I am provided with another dictionary called fileList whose keys are group names and each value is a tuples of file-paths. Each file path will generate one sample in samples by populating the Timeseries item. Further some processing will make GeneratedFeature. The name part will be determined by the filepath.

Since I don't know the contents of fileList a priori, in MATLAB if samples were a struct and fileList just a cell array:

fileList={{'Group A',{'filepath1','filepath2'}};{'Group B',{'filepath1', 'filepath2'}}}

I would just set a counter k=1 and run a for loop (with a different index) and do something like:

for i=1:numel(fileList)
    for j=1:numel(fileList{i}{2})

But I don't know how to do this in python. I know I can keep the two for loop approach with

for (group, samples) in fileList:
   for sample in samples:

But how to tell python that samples is allowed to be an array/list? Is there a more pythonic approach than doing for loop?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.553989 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO