A stupid question, I just want to have a function which is like a subroutine in Fortran.
Just a simple example,
function gauss(theta::Array{Float64,2})
theta = [1.0 1.0 ; 2.0 2.0]
return nothing
end
I just want to input an array theta, then its value needs to be changed to what I set theta = [1.0 1.0 ; 2.0 2.0]. However, when I do
a = [100.0 100.0 ; 200.0 200.0]
gauss(a)
a
I would expect a to be changed to [1.0 1.0 ; 2.0 2.0],
however, result is still a = [100.0 100.0 ; 200.0 200.0]. So a does not changed at all.
I also tried gauss!(a), but the result remain the same as if no ! is added.
Why?
How to change really mutate the arguments in this example, and in general?
function gauss(theta::Float64, beta::Array{Float64,2}, gamma::Int64)
theta = 1.0
beta = [1.0 2.0 ; 3.0 4.0]
gamma = 50
return nothing
end
a = 100.0
b = [0.0 0.0; 0.0 0.0]
c = 10000
gauss(a,b,c)
println(a,b,c)
In the abvoe example, after gauss(a,b,c), the println(a,b,c) still just give the initial values of a, b, c.
100.0[0.0 0.0; 0.0 0.0]10000
This is obviously not what I want.
as @odow pointed out, for array I can use .= , but how about for Float, Int variables?
Thanks in advance, and sorry for the stupid question!