# Why am i getting an array instead of a number

**URL:** <https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711>\
**Category:** General Usage\
**Created:** [March 8, 2020, 6:43am UTC](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711 "2020-03-08T06:43:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [March 8, 2020, 6:43am UTC](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711/1 "2020-03-08T06:43:35Z")

</div>

I have this function that i want to to get a probability from which means that i should get a number but instead of that i’m getting an array with the identical elements.

```julia
function prob(na) #na must be a Vector
		   @assert count(!iszero, ui2*na) == 0 #ui2 is an array
		    b = T0*na #T0 is Array{Float64,2} and na is a Vector
		    setc(-b)
		    total = 0.0
		    for x in Channel(scan)
		        nab = vi2*x + b #vi2 is an array
		        total += prod([c.^complex(n)/factorial(n) for (c, n) in zip(coef, nab)])
		    end
		    return abs2.(total*omega)
		end

```

as an output i get an array and not a number, something like :

```julia
6-element Array{Float64,1}:
 5.241854339937168e-30
 5.241854339937168e-30
 5.241854339937168e-30
 5.241854339937168e-30
 5.241854339937168e-30
 5.241854339937168e-30

```

and i don’t know what is the reason.  
and you can take a further look at the code in this link [Quantum\_Relay/QuantumRelay.jl at master · marouanehanhasse/Quantum\_Relay · GitHub](https://github.com/marouanehanhasse/Quantum_Relay/blob/master/src/QuantumRelay.jl)

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 8, 2020, 7:23am UTC](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711/2 "2020-03-08T07:23:01Z")

</div>

This is a function where nearly none of the variables have been defined, even function definitions are missing.

Firstly, that makes it hard to answer your question, and secondly, it’s it is good programming style to explicitly provide variables as inputs to your function, instead of relying on ‘hidden’ outer state. Thirdly, you should try to provide a fully self-contained example that can be copy-pasted an run by those who want to help you.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 8, 2020, 7:27am UTC](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711/3 "2020-03-08T07:27:31Z")

</div>

In particular, the variable `omega` seems to be crucial here. It’s probably an array, and you haven’t defined it. The fact that `abs2.` is called with a dot, indicates that whoever wrote the code _expects_ it to be an array.

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [March 8, 2020, 1:18pm UTC](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711/4 "2020-03-08T13:18:46Z")

</div>

Actually this function it is a part of a module where i put the link of the module so if anyone who doesn’t know some variable he or she can take a look at the link.  
here is the link to take a look at the code

> <https://github.com/marouanehanhasse/Quantum_Relay/blob/master/src/QuantumRelay.jl>

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [March 8, 2020, 1:31pm UTC](https://discourse.julialang.org/t/why-am-i-getting-an-array-instead-of-a-number/35711/5 "2020-03-08T13:31:59Z")

</div>

i just realised that i didn’t pay attention omega is a coefficient but instead i put it as `omega=[1.0 / prod(cosh(chi))^2 for i=1:n] ` which will give a coefficient n times and i had to define it as `omega= 1.0/prod(cosh.(chi))^2 ` that’s the reason why i was getting an array for a month. 😭
