I have a simple code and a simple question.
it is with type My_w, and a 2-element array www whose type is My_w,
mutable struct My_w
w::Float64
end
www = Array{My_w,1}(undef,2)
Now, I want to set www[1] and www[2] both as My_w(1.0). Can I do it in one line like Fortran did, such as,
www[:] = My_w(1.0)
But obviously this give me an error.
Or, do I have to do a loop for such a simple initialization like below?
for i in 1:2
www[i] = My_w(1.0)
end
Is there a one-line ‘vectorization’ flavor solution instead of writing a loop?
Furthermore, if I have define another 2 elements array A,
A=zeros(2)
Now I want to set the elements of array A as the values of www[:].w, in fortran I can do things like,
A[:] = www[:].w
But in Julia obviously this gives me an error.
Again, in Julia do I have to do
for i in 1:2
A[i] = www[i].w
end
Is there more concise way like Fortran did?
Dear all, as you can see, the : symbol in Fortran seems very powerful actually for array operations.
Thanks in advance!