Skip to content

Memory order like another array #1072

@nilgoyette

Description

@nilgoyette

One of my function needs to create a new array with the same order as the input. I know I can use clone() when both arrays have the same dimension, but when it's not the case, it's more complex.

fn binary_dilation(mask: &Array3<bool>) -> Array3<bool> {
    let (width, height, depth) = mask.dim();
    let dim = (width + etc., ...);
    let mut new_mask = if mask.is_standard_layout() {
        Array3::from_elem(dim, false)
    } else {
        Array3::from_elem(dim.f(), false)
    };
    // Do something
}

Is there a one-liner for this? Something like

Array3::from_elem(dim.order_of(mask), false)

or anytning that doesn't require an if?

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