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.
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 :
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.
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.
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
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.