def _to_struct_of_array()

in pybulletX/_wrapper.py [0:0]


def _to_struct_of_array(array_of_struct):
    """
    utility function that convert array of struct (AoS) to struct of array (SoA),
    which is more suitable for ML application down the road (ex: PyTorch).
    """
    if not array_of_struct:
        return {}
    keys = array_of_struct[0].__dict__.keys()
    return {
        k: _numpy.array([getattr(struct, k) for struct in array_of_struct])
        for k in keys
    }