# \#map

**URL:** https://discourse.julialang.org/tag/map/1075.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [\`map\` should be more consistent](https://discourse.julialang.org/t/map-should-be-more-consistent/132559)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 7\
**Last updated:** [September 23, 2025, 1:31am UTC](https://discourse.julialang.org/t/map-should-be-more-consistent/132559 "2025-09-23T01:31:32Z")

</div>

Dear all, I wonder if it is proper to amend this behavior? julia\> map(\_ -\> 0, 0) 0 julia\> struct Nvmber end julia\> Base.ndims(::Nvmber) = 0 julia\> Base.length(::Nvmber) = 1 julia\> Base.iterate(f::Nvmber) = (f, miss…

---

## [How to make splat, map and tuples be efficient](https://discourse.julialang.org/t/how-to-make-splat-map-and-tuples-be-efficient/125653)

<div class="topic-metadata">

**Author:** [@garazha-ilya](https://discourse.julialang.org/u/garazha-ilya)\
**Replies:** 3\
**Last updated:** [February 7, 2025, 7:08pm UTC](https://discourse.julialang.org/t/how-to-make-splat-map-and-tuples-be-efficient/125653 "2025-02-07T19:08:29Z")

</div>

Generally I want to make f(g("a"), g("c"), g("k")) with f(map(g, \["a","c","k"\])...) be efficient and don’t generate allocations. And I started experimenting, by creating 3 functions: function foo\_tuple(a,b,c) …

---

## [How to map rectangular lat/lon region on non-rectangular projection with GeoMakie?](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140)

<div class="topic-metadata">

**Author:** [@haffner](https://discourse.julialang.org/u/haffner)\
**Replies:** 5\
**Last updated:** [September 30, 2024, 4:06pm UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140 "2024-09-30T16:06:04Z")

</div>

I’m trying to map a rectangular lat/lon polygon on a non-rectangular map projection using GeoMakie, When I use four corner points to define the region, GeoMakie draws straight lines between them. The example below show…

---

## [Why \`map\` requires \`collect\` to use for general iterable things?](https://discourse.julialang.org/t/why-map-requires-collect-to-use-for-general-iterable-things/114748)

<div class="topic-metadata">

**Author:** [@paalon](https://discourse.julialang.org/u/paalon)\
**Replies:** 18\
**Last updated:** [May 28, 2024, 10:05am UTC](https://discourse.julialang.org/t/why-map-requires-collect-to-use-for-general-iterable-things/114748 "2024-05-28T10:05:54Z")

</div>

Why map requires to collect for general iterable things? julia\> foreach(println, "あいうえお") あ い う え お julia\> map(println, "あいうえお"); あ ERROR: ArgumentError: map(f, s::AbstractString) requires f to return AbstractChar; try…

---

## [Replacing components with indices](https://discourse.julialang.org/t/replacing-components-with-indices/113412)

<div class="topic-metadata">

**Author:** [@KeepLearning](https://discourse.julialang.org/u/KeepLearning)\
**Replies:** 12\
**Last updated:** [April 25, 2024, 4:00pm UTC](https://discourse.julialang.org/t/replacing-components-with-indices/113412 "2024-04-25T16:00:55Z")

</div>

I am wondering if the following can be done in a better way (without for loop, perhaps): given a vector and a vector of vectors, e.g. v = \[1, 2, 3, 3, 4, 4, 5\] u = \[\[1,2\], \[3, 5\], \[4\]\] I like to get \[1, 1, 2, 2, 3, 3,…

---

## [Closest cousin of mapview in julia](https://discourse.julialang.org/t/closest-cousin-of-mapview-in-julia/110197)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 1\
**Last updated:** [February 14, 2024, 8:37am UTC](https://discourse.julialang.org/t/closest-cousin-of-mapview-in-julia/110197 "2024-02-14T08:37:41Z")

</div>

The package mapview in R allows one to generate interactive html (with JS) maps, i.e. ones that can be zoomed in and out, moved, shared with others, etcetera. Is there a good alternative in Julia? I’m aware of Leaflet.…

---

## [Using a function on each row of a matrix and getting a similar matrix back](https://discourse.julialang.org/t/using-a-function-on-each-row-of-a-matrix-and-getting-a-similar-matrix-back/109162)

<div class="topic-metadata">

**Author:** [@aris](https://discourse.julialang.org/u/aris)\
**Replies:** 13\
**Last updated:** [January 24, 2024, 2:40pm UTC](https://discourse.julialang.org/t/using-a-function-on-each-row-of-a-matrix-and-getting-a-similar-matrix-back/109162 "2024-01-24T14:40:53Z")

</div>

Suppose we have a function acting on a 3-element vector, function foo(xyz) a = xyz\[1\]+1 b = xyz\[2\]\*5 c = xyz\[3\]/2 return\[a,b,c\] end It works fine if I use a vector as an input, like foo(\[1,2,3\]), but what if I’d l…

---

## [Type instability when using map with closures](https://discourse.julialang.org/t/type-instability-when-using-map-with-closures/101510)

<div class="topic-metadata">

**Author:** [@ynue](https://discourse.julialang.org/u/ynue)\
**Replies:** 3\
**Last updated:** [July 12, 2023, 9:54am UTC](https://discourse.julialang.org/t/type-instability-when-using-map-with-closures/101510 "2023-07-12T09:54:37Z")

</div>

I have observed a surprising behaviour of map with closures. It seems that type instabilities appear when the function called by map overwrites a variable that belongs to an outer scope (only changing its value while kee…

---

## [Colorizing a UInt8 matrix](https://discourse.julialang.org/t/colorizing-a-uint8-matrix/99158)

<div class="topic-metadata">

**Author:** [@mmv](https://discourse.julialang.org/u/mmv)\
**Replies:** 15\
**Last updated:** [May 23, 2023, 11:46pm UTC](https://discourse.julialang.org/t/colorizing-a-uint8-matrix/99158 "2023-05-23T23:46:39Z")

</div>

Hi! I have a UInt8 matrix of 512 lines by 2048 columns where the elements can only take on the values 0x00, 0x01, 0x02, 0x03, 0x04, 0xfd, 0xfe or 0xff. I’d like to visualize this matrix as a color map, ideally in PNG or…

---

## [How to draw a circle of 500m away from a point on a map? or how to highlight all connected ways?](https://discourse.julialang.org/t/how-to-draw-a-circle-of-500m-away-from-a-point-on-a-map-or-how-to-highlight-all-connected-ways/98093)

<div class="topic-metadata">

**Author:** [@Optimization](https://discourse.julialang.org/u/Optimization)\
**Replies:** 5\
**Last updated:** [April 30, 2023, 12:42pm UTC](https://discourse.julialang.org/t/how-to-draw-a-circle-of-500m-away-from-a-point-on-a-map-or-how-to-highlight-all-connected-ways/98093 "2023-04-30T12:42:36Z")

</div>

Is it possible to draw a circle around a coordinates? I knew that with folium one can plot a points on a map: using OpenStreetMapX using PyCall points = LLA(43.658813, -79.397574, 0.0) using PyCall flm = pyimport("f…

---

## [Map over vector with union eltype makes type-inference worse](https://discourse.julialang.org/t/map-over-vector-with-union-eltype-makes-type-inference-worse/97332)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 2\
**Last updated:** [April 12, 2023, 2:15am UTC](https://discourse.julialang.org/t/map-over-vector-with-union-eltype-makes-type-inference-worse/97332 "2023-04-12T02:15:16Z")

</div>

julia\> struct A end julia\> struct B end julia\> struct C{AA,BB} a :: AA b :: BB end julia\> v = Union{C{A,B}, C{B,B}}\[C(A(), B()), C(B(),B())\] 2-element Vector{Union{C{A, B}, C{B, B}}}: C{A, B}(A…

---

## [Generator slow when passed as argument](https://discourse.julialang.org/t/generator-slow-when-passed-as-argument/91606)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 6\
**Last updated:** [December 20, 2022, 3:02am UTC](https://discourse.julialang.org/t/generator-slow-when-passed-as-argument/91606 "2022-12-20T03:02:47Z")

</div>

(Julia 1.9.0-alpha1) Why is this? julia\> @btime let x=(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8) ns=propertynames(x) NamedTuple{ns}(map(n-\>getproperty(x,n), ns)) end 1.000 ns (0 allocations: 0 byt…

---

## [Why is a multi-argument inplace map much faster in this case than a broadcast?](https://discourse.julialang.org/t/why-is-a-multi-argument-inplace-map-much-faster-in-this-case-than-a-broadcast/91525)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 16\
**Last updated:** [December 12, 2022, 7:14pm UTC](https://discourse.julialang.org/t/why-is-a-multi-argument-inplace-map-much-faster-in-this-case-than-a-broadcast/91525 "2022-12-12T19:14:55Z")

</div>

julia\> A = rand(10, 1000); B = copy(A); C = zero(A); D = zero(A); julia\> @btime map!(+, $C, $A, $B); 3.405 μs (0 allocations: 0 bytes) julia\> @btime $D .= $A .+ $B; 10.915 μs (0 allocations: 0 bytes) julia\> A = r…

---

## [Define a \`mapat\` function to map a function over specific indices](https://discourse.julialang.org/t/define-a-mapat-function-to-map-a-function-over-specific-indices/90392)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 3\
**Last updated:** [November 17, 2022, 3:02pm UTC](https://discourse.julialang.org/t/define-a-mapat-function-to-map-a-function-over-specific-indices/90392 "2022-11-17T15:02:42Z")

</div>

I have an Array and want to map a function over selected indices, I tried the following two implementations: # Map function \`f\` at specific indices of an array and update in-place function mapat!(f, array, indices...) …

---

## [Shapes from geojson on geo map with Plotly](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777)

<div class="topic-metadata">

**Author:** [@lgo](https://discourse.julialang.org/u/lgo)\
**Replies:** 5\
**Last updated:** [November 10, 2022, 12:10pm UTC](https://discourse.julialang.org/t/shapes-from-geojson-on-geo-map-with-plotly/89777 "2022-11-10T12:10:55Z")

</div>

I want to plot a geojson with multiple geojsons as a geo map with Plotly. I tried to convert an existing Python example to Julia but without success. The code below is just one example and I’ve also tested the same struc…

---

## [@spawn map(x -\> f(x), collection) only returns Task (Done)](https://discourse.julialang.org/t/spawn-map-x-f-x-collection-only-returns-task-done/89575)

<div class="topic-metadata">

**Author:** [@JohnS](https://discourse.julialang.org/u/JohnS)\
**Replies:** 5\
**Last updated:** [November 1, 2022, 2:46pm UTC](https://discourse.julialang.org/t/spawn-map-x-f-x-collection-only-returns-task-done/89575 "2022-11-01T14:46:23Z")

</div>

Hello! I want to multiply a series of matrices by a vector, and it looks like @spawn is the fastest multithreading process. Unfortunately, the below MWE only returns Task Done. x = collect(1:1:10) y = x .+ x vecmat = …

---

## [Why there is no in-place \`map!\` on arrays?](https://discourse.julialang.org/t/why-there-is-no-in-place-map-on-arrays/87956)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 13\
**Last updated:** [September 29, 2022, 7:57pm UTC](https://discourse.julialang.org/t/why-there-is-no-in-place-map-on-arrays/87956 "2022-09-29T19:57:20Z")

</div>

I am wondering why we could not have a in-place map! so that the destination and the source are the same: julia\> a = \[1, 2, 3\]; julia\> map!(-, a) 3-element Vector{Int64}: -1 -2 -3 I am using this pattern a lot and …

---

## [\`map\` vs \`broadcast\`: should one prefer \`map\` if these are equivalent?](https://discourse.julialang.org/t/map-vs-broadcast-should-one-prefer-map-if-these-are-equivalent/86118)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 3\
**Last updated:** [August 23, 2022, 10:09am UTC](https://discourse.julialang.org/t/map-vs-broadcast-should-one-prefer-map-if-these-are-equivalent/86118 "2022-08-23T10:09:26Z")

</div>

I’m referring to the simplest case where map and broadcast are equivalent, that is – given a vector/tuple, I want to map a function over it to obtain another container. broadcast seems a natural choice here, and map seem…

---

## [How to save function output as a variable?](https://discourse.julialang.org/t/how-to-save-function-output-as-a-variable/85553)

<div class="topic-metadata">

**Author:** [@albrightand](https://discourse.julialang.org/u/albrightand)\
**Replies:** 3\
**Last updated:** [August 9, 2022, 9:11pm UTC](https://discourse.julialang.org/t/how-to-save-function-output-as-a-variable/85553 "2022-08-09T21:11:59Z")

</div>

I’m new to Julia and practicing writing functions… The function below works great, if I call it from the command line like: julia\> prime(5) \[1, 2, 3, 5\] BUT if I try to set the output of the function to a variable, th…

---

## [Different performance between reduce(map()) and mapreduce()](https://discourse.julialang.org/t/different-performance-between-reduce-map-and-mapreduce/85149)

<div class="topic-metadata">

**Author:** [@gwlagerweij](https://discourse.julialang.org/u/gwlagerweij)\
**Replies:** 7\
**Last updated:** [August 2, 2022, 10:55am UTC](https://discourse.julialang.org/t/different-performance-between-reduce-map-and-mapreduce/85149 "2022-08-02T10:55:01Z")

</div>

Hi all, I want to create an array of indices (for creation of a sparse matrix in a later stage) based on a list of element connectivity as follows: N = 10000; # Number of elements ele…

---

## [Type instability in Folds.map](https://discourse.julialang.org/t/type-instability-in-folds-map/84080)

<div class="topic-metadata">

**Author:** [@MattSainsbury-Dale](https://discourse.julialang.org/u/MattSainsbury-Dale)\
**Replies:** 0\
**Last updated:** [July 12, 2022, 3:54am UTC](https://discourse.julialang.org/t/type-instability-in-folds-map/84080 "2022-07-12T03:54:28Z")

</div>

Hello, I’ve noticed that the Folds version of map() seems to introduce type instability: using Folds f1(K::Integer) = map(identity, 1:K) f2(K::Integer) = Folds.map(identity, 1:K) @code\_warntype f1(5) @code\_warntype f…

---

## [Plot Map in Julia](https://discourse.julialang.org/t/plot-map-in-julia/84019)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 9\
**Last updated:** [July 10, 2022, 11:08pm UTC](https://discourse.julialang.org/t/plot-map-in-julia/84019 "2022-07-10T23:08:41Z")

</div>

Hi all, I want to know is it possible to plot map with color for different country by using Julia. like this: Each color could represent certain cluster/grouping. I see mapbox is expensive, we need to have credit c…
