# \#broadcasting

**URL:** https://discourse.julialang.org/tag/broadcasting/249.md

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

---

## [Producing Strings with split()](https://discourse.julialang.org/t/producing-strings-with-split/134954)

<div class="topic-metadata">

**Author:** [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)\
**Replies:** 4\
**Last updated:** [January 8, 2026, 5:29pm UTC](https://discourse.julialang.org/t/producing-strings-with-split/134954 "2026-01-08T17:29:34Z")

</div>

Hi, I would like to avoid getting SubStrings. While the first split can be “fixed”, it “fails” at the second split and I don’t get why. julia\> txt = "a b c-aa bb cc-aaa bbb ccc" "a b c-aa bb cc-aaa bbb ccc" julia\> li…

---

## [Semantically equivalent expressions with wildly different performance](https://discourse.julialang.org/t/semantically-equivalent-expressions-with-wildly-different-performance/131123)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 10\
**Last updated:** [July 28, 2025, 2:54pm UTC](https://discourse.julialang.org/t/semantically-equivalent-expressions-with-wildly-different-performance/131123 "2025-07-28T14:54:10Z")

</div>

I came across the following example when I needed something that beats the performance of LinearAlgebra’s build in mul!(M, x, y'). Any known reason for this huge difference in performance? Tested on 11.6. using Benchmar…

---

## [BroadcastStyle of a SubArray](https://discourse.julialang.org/t/broadcaststyle-of-a-subarray/128181)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 0\
**Last updated:** [April 18, 2025, 7:50am UTC](https://discourse.julialang.org/t/broadcaststyle-of-a-subarray/128181 "2025-04-18T07:50:46Z")

</div>

The broadcast style of SubArrray (i.e. as obtained using view) is a DefaultArrayStyle: julia\> Base.BroadcastStyle(typeof(view(rand(10,10),2:3,3:4))) Base.Broadcast.DefaultArrayStyle{2}() yet it would be extremely usefu…

---

## [Adapt BroadcastStyle for CUDA](https://discourse.julialang.org/t/adapt-broadcaststyle-for-cuda/126861)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 1\
**Last updated:** [March 18, 2025, 5:50pm UTC](https://discourse.julialang.org/t/adapt-broadcaststyle-for-cuda/126861 "2025-03-18T17:50:40Z")

</div>

I am trying to get CUDA.jl to work seamlessly with a MutableShiftedArray . By writing a CUDASupportExt.jl class: module CUDASupportExt using CUDA using Adapt using MutableShiftedArrays indexing CUDA error # lets do t…

---

## [Avoid writing exponentially many methods for a function that may take vectors or matrices](https://discourse.julialang.org/t/avoid-writing-exponentially-many-methods-for-a-function-that-may-take-vectors-or-matrices/125895)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 3\
**Last updated:** [February 14, 2025, 1:14pm UTC](https://discourse.julialang.org/t/avoid-writing-exponentially-many-methods-for-a-function-that-may-take-vectors-or-matrices/125895 "2025-02-14T13:14:50Z")

</div>

Hi, in my current project I need to compute a function, say f, in N inputs, which all may be either vectors or matrices. In terms of interpretation: a vector is an ‘observation’, and a matrix is a set of observations, wh…

---

## [If in === ∈, why does .∈ work but .in fails with a ParseError?](https://discourse.julialang.org/t/if-in-why-does-work-but-in-fails-with-a-parseerror/125464)

<div class="topic-metadata">

**Author:** [@Matheus](https://discourse.julialang.org/u/Matheus)\
**Replies:** 5\
**Last updated:** [February 2, 2025, 1:02pm UTC](https://discourse.julialang.org/t/if-in-why-does-work-but-in-fails-with-a-parseerror/125464 "2025-02-02T13:02:59Z")

</div>

Hello everyone, I’m trying to understand the following behavior regarding in and ∈ (I guess they’re called operators?). While they are functionally identical (in === ∈ returns true), they behave differently when used wi…

---

## [Broadcast matrix valued function, output into existing array](https://discourse.julialang.org/t/broadcast-matrix-valued-function-output-into-existing-array/124831)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 7\
**Last updated:** [January 17, 2025, 6:42am UTC](https://discourse.julialang.org/t/broadcast-matrix-valued-function-output-into-existing-array/124831 "2025-01-17T06:42:50Z")

</div>

How do I broadcast the function matop below such that the output car1 resembles car, i.e., car1 is an array which can be accessed as car1\[:,1,2\]? Presently, car1 looks like a vector, with size (N,), instead of (N,2,2). …

---

## [In-place broadcasting for a specific function](https://discourse.julialang.org/t/in-place-broadcasting-for-a-specific-function/124680)

<div class="topic-metadata">

**Author:** [@arnaud-ma](https://discourse.julialang.org/u/arnaud-ma)\
**Replies:** 8\
**Last updated:** [January 12, 2025, 3:40am UTC](https://discourse.julialang.org/t/in-place-broadcasting-for-a-specific-function/124680 "2025-01-12T03:40:03Z")

</div>

My code is as follows: function get\_foo(x, y, args...) # specific algorithm that modifies x and y... return x + y end function gen\_foo!(A::AbstractMatrix, args...) # is equivalent to: for coord in Carte…

---

## [AbstractArrayStyle{Any} versus AbstractArrayStyle{N} broadcast style](https://discourse.julialang.org/t/abstractarraystyle-any-versus-abstractarraystyle-n-broadcast-style/124526)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [January 8, 2025, 8:40pm UTC](https://discourse.julialang.org/t/abstractarraystyle-any-versus-abstractarraystyle-n-broadcast-style/124526 "2025-01-08T20:40:33Z")

</div>

Suppose a package defines an array type SomeArray which, like Array, supports arbitrary dimensionality: struct SomeArray{N} \<: AbstractArray{Float32, N} end # the element type doesn't matter here, it's merely an exampl…

---

## [Broadcasting performance](https://discourse.julialang.org/t/broadcasting-performance/123392)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 13\
**Last updated:** [January 6, 2025, 9:39am UTC](https://discourse.julialang.org/t/broadcasting-performance/123392 "2025-01-06T09:39:27Z")

</div>

f(x) = sin(x)cos(x)tan(x)exp(x)sin(x)cos(x)tan(x)exp(x) X = randn(100\_000\_000) @time f.(X) # 4 seconds @time @threads for x in X; f(x) end # .8 seconds 16 threads @time @turbo f.(X) …

---

## [Broadcasting the reshaped data @. versus .=](https://discourse.julialang.org/t/broadcasting-the-reshaped-data-versus/124300)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 13\
**Last updated:** [January 1, 2025, 11:48am UTC](https://discourse.julialang.org/t/broadcasting-the-reshaped-data-versus/124300 "2025-01-01T11:48:39Z")

</div>

I am rewriting this code below using broadcasting to improve performance and clarity. var = zeros(Float64, 9, 109, 50) data = rand(9\*109\*50) for j in 1:9 # Extract the slice of data corresponding to the current \`j\` …

---

## [Broadcasting question](https://discourse.julialang.org/t/broadcasting-question/122092)

<div class="topic-metadata">

**Author:** [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Replies:** 4\
**Last updated:** [October 31, 2024, 8:15pm UTC](https://discourse.julialang.org/t/broadcasting-question/122092 "2024-10-31T20:15:14Z")

</div>

I’m trying to calculate the following: where v and \\hat{n} vectors of length 3. But I need to do this to a bunch of vectors stored in a Vector{Vector{SVector{3,Float64}}} I ended up doing it like this: dots = \[\[ve…

---

## [Understanding @report\_code output](https://discourse.julialang.org/t/understanding-report-code-output/116000)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 3\
**Last updated:** [June 23, 2024, 6:56pm UTC](https://discourse.julialang.org/t/understanding-report-code-output/116000 "2024-06-23T18:56:25Z")

</div>

Hi there, This is my first time using JET.jl to fix the type-instability issues of my code. I am aware that maybe asking without a reproducible example might be a stretch but I will try anyways. My function takes as an…

---

## [Efficient weighted sum for arbitrary data types](https://discourse.julialang.org/t/efficient-weighted-sum-for-arbitrary-data-types/113992)

<div class="topic-metadata">

**Author:** [@baxmittens](https://discourse.julialang.org/u/baxmittens)\
**Replies:** 7\
**Last updated:** [May 9, 2024, 11:26am UTC](https://discourse.julialang.org/t/efficient-weighted-sum-for-arbitrary-data-types/113992 "2024-05-09T11:26:58Z")

</div>

Hello all, I have some old Julia code, e.g., DistributedSparseGrids.jl, written in 2016, which uses in-place math operations on custom data types implemented by proprietary in-place operator functions. The task I alw…

---

## [Get a vector from field](https://discourse.julialang.org/t/get-a-vector-from-field/110713)

<div class="topic-metadata">

**Author:** [@mary](https://discourse.julialang.org/u/mary)\
**Replies:** 4\
**Last updated:** [February 25, 2024, 10:12pm UTC](https://discourse.julialang.org/t/get-a-vector-from-field/110713 "2024-02-25T22:12:57Z")

</div>

hi I wrote this code in julia gridap. h value is a field. i need a vector of values. how can i get that? ∂Hn+1/∂hnj={−1 , if i = j and ψ+n+1(e (ξ i ) )\< hn(ξ i ) 0 , otherwise function dh(hh\_in, ψPlusnext\_in) h\_…

---

## [.. broadcast object property](https://discourse.julialang.org/t/broadcast-object-property/47104)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 41\
**Last updated:** [February 15, 2024, 8:21am UTC](https://discourse.julialang.org/t/broadcast-object-property/47104 "2024-02-15T08:21:52Z")

</div>

A few years back I requested … be used to broadcast object property over array of objects. If A.x is property x of object A. Then Array\_of\_A…x is an array of the x properties of the A objects. Was told … was al…

---

## [Tullio broadcasting issue](https://discourse.julialang.org/t/tullio-broadcasting-issue/107321)

<div class="topic-metadata">

**Author:** [@swanchristmas](https://discourse.julialang.org/u/swanchristmas)\
**Replies:** 4\
**Last updated:** [December 9, 2023, 11:46am UTC](https://discourse.julialang.org/t/tullio-broadcasting-issue/107321 "2023-12-09T11:46:28Z")

</div>

@tensor tmp1\[m,s,n,p\] := -λ\[l,m,s\]\*ω\[l,k\]\*λ\[k,n,p\] + λ\[l,m,s\]\*g\[l,n\]\*ones(2)\[p\]) @tullio tmp2\[m,s,n,p\] := -λ\[l,m,s\]\*ω\[l,k\]\*λ\[k,n,p\] + λ\[l,m,s\]\*g\[l,n\] tmp1 turns out to be different from tmp2. It seems that @tullio perfo…

---

## [Curried Broadcasting Comparison Operators](https://discourse.julialang.org/t/curried-broadcasting-comparison-operators/90613)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 5\
**Last updated:** [October 4, 2023, 8:18pm UTC](https://discourse.julialang.org/t/curried-broadcasting-comparison-operators/90613 "2023-10-04T20:18:19Z")

</div>

This is not what I expected: julia\> \>(2) === .\>(2) true julia\> .\>(1:4) 4-element Vector{Base.Fix2{typeof(\>), Int64}}: (::Base.Fix2{typeof(\>), Int64}) (generic function with 1 method) (::Base.Fix2{typeof(\>), Int64}) (…

---

## [Assignment into array of arrays by broadcasting](https://discourse.julialang.org/t/assignment-into-array-of-arrays-by-broadcasting/91072)

<div class="topic-metadata">

**Author:** [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Replies:** 12\
**Last updated:** [July 6, 2023, 9:45pm UTC](https://discourse.julialang.org/t/assignment-into-array-of-arrays-by-broadcasting/91072 "2023-07-06T21:45:19Z")

</div>

I want to simulate a process with 3 discrete outcomes. Let’s say they have probabilities .2, .3 and .5 and I want to run nSim = 10 simulations, each of which is a series of nDraw = 5 draws from the discrete distribution…

---

## [Broadcast update multiple vectors at once](https://discourse.julialang.org/t/broadcast-update-multiple-vectors-at-once/99490)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 7\
**Last updated:** [May 28, 2023, 7:24am UTC](https://discourse.julialang.org/t/broadcast-update-multiple-vectors-at-once/99490 "2023-05-28T07:24:51Z")

</div>

Simple question. I have a few vectors which hold the states of a list of particles. I update these with broadcast (which is nice since the vectors are on the GPU). For example: position⁰ .= position position .+=…

---

## [Why Julia is giving a different answer than r?](https://discourse.julialang.org/t/why-julia-is-giving-a-different-answer-than-r/98918)

<div class="topic-metadata">

**Author:** [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Replies:** 5\
**Last updated:** [May 16, 2023, 9:30am UTC](https://discourse.julialang.org/t/why-julia-is-giving-a-different-answer-than-r/98918 "2023-05-16T09:30:19Z")

</div>

i have a simple equation as given below (julia code). I’m getting different answer as compare to r. Am I missing something? x=100 y=0 d = 20 h = -2 c = \[0, 1, 2, 3, 4, 5\] A = x .+ ((y - x) / (1 .+ (c / d).^h)) answer i…

---

## [Collecting Base.Broadcast.Broadcasted](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 2\
**Last updated:** [April 26, 2023, 9:59am UTC](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933 "2023-04-26T09:59:51Z")

</div>

when overloading broadcasted() one may sometimes want to call collect. However, this seems to not remember the size: julia\> a = reshape(1:100,(10,10)) 10×10 reshape(::UnitRange{Int64}, 10, 10) with eltype Int64: 1 11…

---

## [Redefining a single function broadcast rule?](https://discourse.julialang.org/t/redefining-a-single-function-broadcast-rule/97890)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 2\
**Last updated:** [April 25, 2023, 10:01am UTC](https://discourse.julialang.org/t/redefining-a-single-function-broadcast-rule/97890 "2023-04-25T10:01:01Z")

</div>

I would like to redefine a single broadcast rule relating to the coalesce. broadcast. The reason is that the ShiftedArray type can return missing or nothing for out-of-bound shifted access. If the user uses coalesce.(my…

---

## [Specifying broadcast in reduce operations](https://discourse.julialang.org/t/specifying-broadcast-in-reduce-operations/97589)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 5\
**Last updated:** [April 25, 2023, 6:43am UTC](https://discourse.julialang.org/t/specifying-broadcast-in-reduce-operations/97589 "2023-04-25T06:43:48Z")

</div>

Writing a new CircShiftedArrays package that specified its own BroadcastStyle, I have the trouble that reduce operations such as sum do not get affected by my overloaded functions. I overloaded copyto! and materialize! …

---

## [Understand vectorized dot operators](https://discourse.julialang.org/t/understand-vectorized-dot-operators/96388)

<div class="topic-metadata">

**Author:** [@ahmed-desoki](https://discourse.julialang.org/u/ahmed-desoki)\
**Replies:** 8\
**Last updated:** [March 21, 2023, 3:25pm UTC](https://discourse.julialang.org/t/understand-vectorized-dot-operators/96388 "2023-03-21T15:25:10Z")

</div>

Dear folks I’m an old Matlab user who is trying to switch to Julia. In Matlab, I use array (element-wise) arithmetic a lot. When I tried to make element-wise arithmetic using Julia, I noticed the following strange beha…

---

## [Performance scaling of broadcasting compared to looping](https://discourse.julialang.org/t/performance-scaling-of-broadcasting-compared-to-looping/92000)

<div class="topic-metadata">

**Author:** [@f.ij](https://discourse.julialang.org/u/f.ij)\
**Replies:** 19\
**Last updated:** [March 21, 2023, 11:24am UTC](https://discourse.julialang.org/t/performance-scaling-of-broadcasting-compared-to-looping/92000 "2023-03-21T11:24:56Z")

</div>

I’m writing a simulation where speed is very important. The program consists of a main loop where I need to collect some scalar by multiplying some floats based on connections in an adjacency matrix. As a very simplified…

---

## [Lazy broadcasting speed issues](https://discourse.julialang.org/t/lazy-broadcasting-speed-issues/94218)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 13\
**Last updated:** [March 12, 2023, 4:52pm UTC](https://discourse.julialang.org/t/lazy-broadcasting-speed-issues/94218 "2023-03-12T16:52:22Z")

</div>

I am working on a new package called SeparableFunctions.jl with the aim to boost the performance for functions which are expensive to calculate on multidimensional grids, but can profit a lot from broadcasting. To this…

---

## [Why is identity on an Any vector so much slower when broadcasting than when mapped?](https://discourse.julialang.org/t/why-is-identity-on-an-any-vector-so-much-slower-when-broadcasting-than-when-mapped/95569)

<div class="topic-metadata">

**Author:** [@numberMX](https://discourse.julialang.org/u/numberMX)\
**Replies:** 7\
**Last updated:** [March 7, 2023, 8:16am UTC](https://discourse.julialang.org/t/why-is-identity-on-an-any-vector-so-much-slower-when-broadcasting-than-when-mapped/95569 "2023-03-07T08:16:58Z")

</div>

In the REPL I was experimenting with a function that returns Vector{Any}, and I wanted to see how I could make Julia “automatically” change the type to a fixed type without having to specify it myself. I noticed that eve…

---

## [Tying a function to an array when I get the value of the array](https://discourse.julialang.org/t/tying-a-function-to-an-array-when-i-get-the-value-of-the-array/94354)

<div class="topic-metadata">

**Author:** [@LolianSh](https://discourse.julialang.org/u/LolianSh)\
**Replies:** 4\
**Last updated:** [February 9, 2023, 6:00pm UTC](https://discourse.julialang.org/t/tying-a-function-to-an-array-when-i-get-the-value-of-the-array/94354 "2023-02-09T18:00:28Z")

</div>

Hi everyone, I have question. Maybe someone has encountered this before and can help me out. I would like to do the following: searchsortedfirst(ntoh.(v), x) Assuming v is a memory mapped vector on disk. Using ntoh.(…

---

## [Broadcasting string $variable](https://discourse.julialang.org/t/broadcasting-string-variable/93488)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 12\
**Last updated:** [January 27, 2023, 5:36pm UTC](https://discourse.julialang.org/t/broadcasting-string-variable/93488 "2023-01-27T17:36:05Z")

</div>

Is it possible to do something like this: ."X$(1:3)" and get @\_ "X$\_".(1:3) = \["X1","X2","X3"\] That is, can a vector variable within a string (via $) create a vector of strings. One for each element.

[Next page](https://discourse.julialang.org/tag/broadcasting/249.md?match_all_tags=true&page=1&tags%5B%5D=broadcasting)
