If I have an array A with random values, I would like define an array B with, for each i in length A, B[i] = (A[i])²
First, I tried the following code:
using Distributions
A = rand(Uniform(1,10),1,20)
B = A
for i in 1:20
B[i] = (A[i])^2
end
After these operations, I have A = B
A
1×20 Array{Float64,2}:
26.0478 5.36654 99.675 23.18 … 1.54846 91.3444 9.41496 2.91666
B
1×20 Array{Float64,2}:
26.0478 5.36654 99.675 23.18 … 1.54846 91.3444 9.41496 2.91666
So I tried an other method:
B = A^2
There is the following error:
ERROR: DimensionMismatch("A has dimensions (1,20) but B has dimensions (1,20)")
If I do, for instance, B = 2*A
it works fine...
Some ideas to help ?
Thank you