Awesome
LazyGrids.jl
A Julia package for representing multi-dimensional grids.
https://github.com/JuliaArrays/LazyGrids.jl
Methods
This package exports the following methods:
ndgrid
: a "lazy" version ofndgrid
that returns a tuple ofAbstractArray
objects essentially instantly with just a few bytes of memory allocated.ndgrid_array
: return a traditional tuple ofArray
objects, which takes much longer to create and can use a lot of memory. It is not recommended, but is included for comparison purposes.
See the documentation linked in the blue badges above for examples,
and for a 1-line lazy version of meshgrid
.
As shown in the examples, the lazy version typically is as fast,
if not faster, than using conventional dense Array
objects.
Example
julia> using LazyGrids
(xg, yg) = ndgrid(1:2, 3:0.5:4)
([1 1 1; 2 2 2], [3.0 3.5 4.0; 3.0 3.5 4.0])
julia> xg
2×3 LazyGrids.GridUR{Int64, 1, 2}:
1 1 1
2 2 2
julia> yg
2×3 LazyGrids.GridSL{Float64, 2, 2, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}:
3.0 3.5 4.0
3.0 3.5 4.0
julia> x = range(-1,1,1001)
-1.0:0.002:1.0
julia> (xg, yg, zg) = ndgrid(x, x, x)
{... lots of output ...}
julia> size(xg) # show array dimensions
(1001, 1001, 1001)
julia> sizeof(xg) # show number of bytes used
72
Related packages
- https://github.com/JuliaArrays/LazyArrays.jl
- https://github.com/mcabbott/LazyStack.jl
- https://github.com/ChrisRackauckas/VectorizedRoutines.jl
- https://github.com/JuliaArrays/RangeArrays.jl
Compatibility
Tested with Julia ≥ 1.10.
<!-- URLs -->