1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Normalise across multi-dimensional array

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I have large multi-dimensional array data that at its most basic looks something like this:

    [
    {
    'a': 'a1',
    'b': [
    {
    'ba': 'ba1',
    'bb': 1,
    'bc': {
    'bca': 'bca1',
    'bcb': 4
    }
    },
    {
    'ba': 'ba2',
    'bb': 2,
    'bc': {
    'bca': 'bca2',
    'bcb': 5
    }
    },
    {
    'ba': 'ba3',
    'bb': 3,
    'bc': {
    'bca': 'bca3',
    'bcb': 6
    }
    }
    ]
    },
    ...
    ]


    and what I want to do is to normalise the "bb" and "bcb" values within each object in the top-level array.

    That is, I want to end up with this:

    [
    {
    'a': 'a1',
    'b': [
    {
    'ba': 'ba1',
    'bb': 0,
    'bc': {
    'bca': 'bca1',
    'bcb': 0
    }
    },
    {
    'ba': 'ba2',
    'bb': 0.5,
    'bc': {
    'bca': 'bca2',
    'bcb': 0.5
    }
    },
    {
    'ba': 'ba3',
    'bb': 1,
    'bc': {
    'bca': 'bca3',
    'bcb': 1
    }
    }
    ]
    },
    ...
    ]


    Is there a package or similar I can do this with in python?

    Obviously I can do this with a complicated loop, but I am wondering if there is a more efficient way of doing this?

    Continue reading...

Compartilhe esta Página