Julia function return wrong value than expected

Viewed 68

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!

1 Answers

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

Related