Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy Integration #98

Open
poledna opened this issue Nov 10, 2023 · 0 comments
Open

Numpy Integration #98

poledna opened this issue Nov 10, 2023 · 0 comments

Comments

@poledna
Copy link

poledna commented Nov 10, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant