# Assigning to a view of an array

**URL:** <https://discourse.julialang.org/t/assigning-to-a-view-of-an-array/132869>\
**Category:** New to Julia\
**Tags:** arrays, views\
**Created:** [October 3, 2025, 10:27pm UTC](https://discourse.julialang.org/t/assigning-to-a-view-of-an-array/132869 "2025-10-03T22:27:01Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [October 4, 2025, 1:21pm UTC](https://discourse.julialang.org/t/assigning-to-a-view-of-an-array/132869/12 "2025-10-04T13:21:20Z")

</div>

Thanks, very useful! I’ve bookmarked this usage.

I still don’t understand why there isn’t a _functional_ API counterpart.  
I tried some methods which doesn’t produce good results in terms of performance

```julia
import Random.seed! as seed!
N = 9999

seed!(1);
a = -rand(N, N);
seed!(2);
@time @. a = rand(); # 0.103707 seconds

seed!(1);
a = -rand(N, N);
seed!(2);
@time broadcast!(_ -> rand(), a, a); # 0.160028 seconds (150.04 k allocations: 7.617 MiB, 42.89% compilation time)

seed!(1);
a = -rand(N, N);
seed!(2);
@time foreach(i -> setindex!(a, rand(), i), eachindex(a)); # 3.865129 seconds (199.97 M allocations: 2.980 GiB, 19.73% gc time, 0.30% compilation time)

```

> [@DNF](#):
>
> An alternative syntax is `rand!(sX)`, but that is not as general, since `sX .= f.()` will automatically work for _any_ function `f` (with a compatible return type), while `f!(sX)` would need to be implemented specially.

is the current `sX .= f.()` style (or `@. sX = f()`) very flexible then? I doubt this is something still to be determined.

My doubt is because, sometimes, I need to pass an address to an API:  
for example, the last arg `view(X, j)` here is an address

```julia
Gurobi.GRBgetdblattrelement(o, "X", 
        Gurobi.c_column(o, JuMP.index(x[j])),
        view(X, j))

```

in my this post [Efficiently Retrieving Variable Values after Gurobi optimization with JuMP - #23 by WalterMadelim](https://discourse.julialang.org/t/efficiently-retrieving-variable-values-after-gurobi-optimization-with-jump/127049/23).

In this circumstance I can’t figure out a way to use the highly efficient dot syntax.

---

_[View the full topic](https://discourse.julialang.org/t/assigning-to-a-view-of-an-array/132869)._
