# Get a vector from field

**URL:** <https://discourse.julialang.org/t/get-a-vector-from-field/110713>\
**Category:** New to Julia\
**Tags:** broadcasting, vector, gridap\
**Created:** [February 24, 2024, 10:02pm UTC](https://discourse.julialang.org/t/get-a-vector-from-field/110713 "2024-02-24T22:02:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mary/32/53139_2.png) [@mary](https://discourse.julialang.org/u/mary)\
**Post date:** [February 24, 2024, 10:02pm UTC](https://discourse.julialang.org/t/get-a-vector-from-field/110713/1 "2024-02-24T22:02:06Z")

</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

```julia
function dh(hh_in, ψPlusnext_in)
    h_in = hh_in
    if h_in > ψPlusnext_in
        dh_out = -1.0
    else
        dh_out = 0.0
    end
    dh_out
end

```

how can i have dh\_out as a vector?  
Thank you

---

<div class="post-metadata">

**Author:** ![mary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mary/32/53139_2.png) [@mary](https://discourse.julialang.org/u/mary)\
**Post date:** [February 24, 2024, 10:03pm UTC](https://discourse.julialang.org/t/get-a-vector-from-field/110713/2 "2024-02-24T22:03:20Z")

</div>

I also cant define the -1 and 0 in function as vectors because then it can not do the comparison for if condition

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [February 25, 2024, 6:50am UTC](https://discourse.julialang.org/t/get-a-vector-from-field/110713/3 "2024-02-25T06:50:23Z")

</div>

You can apply any function to an array by using broadcasting, in your case:

```julia
hh_in = rand(10)
ψPlusnext_in = rand(10)
dh_out = dh.(hh_in, ψPlusnext_in)

```

In this particular case, you could also write

```julia
x = rand(10)
y = rand(10)
z = @. (x > y) * -1.0

```

where the `@.` makes sure that all following operations are broadcasted, e.g. applied to each component.

---

<div class="post-metadata">

**Author:** ![mary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mary/32/53139_2.png) [@mary](https://discourse.julialang.org/u/mary)\
**Post date:** [February 25, 2024, 5:24pm UTC](https://discourse.julialang.org/t/get-a-vector-from-field/110713/4 "2024-02-25T17:24:53Z")

</div>

Thank you for your response i did what you said but the output is operationcellfield not a vector. Did i miss something?

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [February 25, 2024, 10:12pm UTC](https://discourse.julialang.org/t/get-a-vector-from-field/110713/5 "2024-02-25T22:12:57Z")

</div>

Oh, sorry, I didn’t read the GridAp.jl specific part. Maybe it would help to see what types exactly you have. You might want to apply it directly to `dd_h.cell_dof_values`.
