Marouane1994
Marouane1994

Reputation: 534

why do i get MethodError: objects of type Float64 are not callable?

i have this function:

function prob(q, na, mask)
            q0 = round(Int, q.>0)
            m0 = round(Int, mask)
            return prod((q0 + (1-2q0).*pdet0(na)).^m0)
        end

where pdet0()is another function, when i want to call the function i see a MethodError: objects of type Float64 are not callable, apparently the error is in the last line of the function and it has something to do with placing the variable before a parenthesized expression but i really can't see it because it looks fine for me.

Upvotes: 1

Views: 2969

Answers (2)

Nils Gudat
Nils Gudat

Reputation: 13800

As Kristoffer says, it's hard to say definitely given that your example doesn't run, but the culprit is most likely pdet0(na) which is interpreted as "call the function pdet0 with the argument na.

In all likelihood, pdet0 is a Float64 number in your code, giving rise to the error. A minimum working example to reproduce the error would be:

julia> function1 = 1.0
1.0

julia> function1(5)
ERROR: MethodError: objects of type Float64 are not callable
Stacktrace:
 [1] top-level scope at REPL[2]:1

You need to have a think about what pdet0 is and why you're trying to call it. Do you by any chance come from Matlab and are trying to index into vector pdet0? This would be pdet0[na] in Julia, which will work if pdet0 is a vector and na and Integer.

Upvotes: 3

Kristoffer Carlsson
Kristoffer Carlsson

Reputation: 2838

You need to provide all the information needed to run the function and reproduce the error. What is q, na, mask? What is pdet0?

Upvotes: 3

Related Questions