Wenlong Zhang
Wenlong Zhang

Reputation: 35

Julia function return wrong value than expected

I am trying to create a function in Julia to initialize an array. Here is my code:

function create_A(i)
   A = zeros(4,1)
   A[i,1] = 1.0
   return A
end
create_A(3)

I was expecting to get [0.0, 0.0, 1.0, 0.0], but instead, I get 6. I am totally confused. Can anyone explain why?

Thanks!

Upvotes: 2

Views: 138

Answers (1)

Oscar Smith
Oscar Smith

Reputation: 6378

You have defined another more specific method for create_A in your Julia session. You can look at all methods with methods(create_A)

Upvotes: 3

Related Questions