Skip to content

Numpy Integration #98

@poledna

Description

@poledna

Hi,

Ive been using Munch and i love it, but i am missing a Munch numpy implementation.
what i have been doing recently is checking recursively all munches related to possible lists. When it finds a list it gets converted to numpy.
This is quite helpful for me, idk if is there a method that i have missed, but it is something that could be useful to the repo as a flag, such as lists2numpy when creating the munch.

    def convert_YAML2Struct(self, yaml):
        data = DefaultMunch.fromDict(yaml)
        for name in dir(data):
            current_key = getattr(data, name)
            setattr(data, name, self.check_munch_key(current_key))
            setattr(self, name, getattr(data, name))

    def check_munch_key(self, current_key):
        for i in dir(current_key):
            if isinstance(getattr(current_key, i), list):
                setattr(current_key, i, np.array(getattr(current_key, i)))
            elif isinstance(getattr(current_key, i), munch.DefaultMunch):
                setattr(current_key, i, self.check_munch_key(getattr(current_key, i)))
        return current_key

Best Regards,
Yuri

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions