Skip to content

Improve documentation or add methods for conversion from nested Vec/ArrayBase #609

Closed
@jturner314

Description

@jturner314

A somewhat frequently-requested feature (e.g. #197, #590, #607) is to provide methods to create Array instances from nested Vec and/or ArrayBase instances (e.g. Array2<A> from Vec<Vec<A>> or Array3<A> from Vec<Array2<A>>).

Note that it's generally advisable to avoid nested Vec/ArrayBase types like this because they require extra heap allocations, can scatter data all over memory, cause unnecessary indirection, fail to enforce consistent shape within the nested Vecs/ArrayBases, and are generally more difficult to work with.

I think we should:

  • Improve the documentation to explain why these nested data structures are best avoided and the best way to handle the use cases (primarily constructing an Array by appending rows).
  • For users who need to use nested data structures anyway, either add the methods to perform the conversions or suggest how they could perform the conversion manually. (data.iter().flatten().cloned().collect::<Vec<_>>() followed by from_shape_vec seems pretty clean if the user is confident that the nested Vecs/ArrayBases are all the same length/shape).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions