Skip to content

Implementation of numpy's meshgrid function for ndarray #1355

Description

@jreniel

I have made an attempt to try to replicate the core functionality of numpy's meshgrid function, using ndarray.
My attempt, which seems to be yielding identical results to the numpy version is hosted here.

My hope is that this function, or an equivalent, makes it to ndarray, since I feel like meshgrid is one of those core numpy functions that we tend to use repeatedly in my field, and it would be an invaluable addition to the ndarray crate.

To be clear, I'm asking to not necessarily use the same function that I've posted here, I'll be happy too if the ndarray devs implement a better solution. All I would like to see is to have this function be a part of the ndarray collection of functions.

Activity

  1. ivnsch commented on Jan 14, 2025

    @ivnsch

    Any updates on this? I also need meshgrid in rust.

  2. akern40 commented on Jan 31, 2025

    @akern40
    Collaborator

    @jreniel, thank you for the reference implementation! @ivnsch and jreniel, do your applications require mesh grid with an arbitrary (i.e., run-time) number of arrays? This dictates whether we can maintain the dimensionality of the output arrays in the type system, or whether we have to resort to ArrayD like jreniel's approach. Let me know; I have a working implementation that works for up to six meshgrid inputs and avoids heap allocations, and I think I can make it work for dynamic-dimensional arrays if needed.

  3. ivnsch commented on Jan 31, 2025

    @ivnsch

    @akern40 sounds great! my current use case requires only a fixed number of arrays (3).

  4. jreniel commented on Jan 31, 2025

    @jreniel
    Author

    Hi @akern40 , sounds like great news that you are working on this!

    I work with ocean and atmospheric spatial data, We often use 2D meshgrids for representing surface data, such as building rasters for bathymetry or other types of data, but the need to represent 3D water/atmos column data is also present and common.
    What I can think of is that it would be nice to have both meshgrid2D and meshgrid3D versions. ND is probably an overkill, but who knows if anyone would need that in practice? (maybe some mathematicians involved in higher dimensional computations/numerics?)

    Thanks again, I'm excited to know that the Rust language just keeps growing! =)

  5. akern40 commented on Jan 31, 2025

    @akern40
    Collaborator

    Thanks to you both for the quick responses! I'll see if I can get a PR open to add this over the weekend.

  6. akern40 commented on Feb 1, 2025

    @akern40
    Collaborator

    Alright, draft is up; I'd written it to be compatible with the array reference implementation in #1440, so we need to get that merged in first. But if you need it immediately, you can use the branch in #1477; it should otherwise pass all CI/CD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions