Dear all,
a simple question that could however help me a lot with my Monte Carlo
codings I’m developping in Julia. The fact is that I need to be able
to modify values from an array in several ways. Iagine I have the
following array
z = [1,2,3,4,5]
then I copy it to zz
zz = z
if now I modify any element either in z or in zz, both z and zz see
the modification
zz[1] = 0
z
prints
5-element Array{Int64,1}:
0
2
3
4
5
z[1] = 1
zz
prints
5-element Array{Int64,1}:
1
2
3
4
5
as expected.
This works very well as I want
Now I need to do similar things BUT with n-dimensional arrays. Assume
I have an array of the form
M = ones(5,2)
2×5 Array{Float64,2}:
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
first index is particle number, second is dimension. Now I need to be
able to refer to whole particle vectors, and be able to make
modifications to it such that they keep in M. And viceversa: make
modifications in M and get them reflected in the vectors. As an
exemple, one could think of
r = M[:,3]
and then be able to do something like
r = [0.0, 0.0]
and recover
M
2×5 Array{Float64,2}:
1.0 1.0 0.0 1.0 1.0
1.0 1.0 0.0 1.0 1.0
which does not work. And the other way around, make
M[:,2] = [2.0,2.0]
and get
r
2-element Array{Float64,1}:
2.0
2.0
Can this be done? Can this r vector be also part of a type
deffinition?
Thanks a lot,
Ferran.