Skip to content

Unzip array of tuples #1463

@niklasmueboe

Description

@niklasmueboe

I have a function that I am mapping along an axis of an array to reduce it, but it doesn't return a single value but rather a tuple.

let tuple_values = arr.map_axis(Axis(0), reduce_to_tuple);

To get the values as separate arrays I am currently doing this
let val1 = tuple_values.mapv(|(x, _)| x);
let val2 = tuple_values.mapv(|(_, x)| x);

I was wondering whether there is a simpler way to unzip an array of tuples, e.g. along the lines of

let (val1, val2) = arr.map_axis(Axis(0), reduce_to_tuple).unzip();

ALos it isn't necessarily a 2-tuple but could be e.g. a 3-tuple, ...

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