If what you want is to raise each individual element to that power, (e.g.
to result in Int64[1,4,9,16]) then what you want is the .^ operator:

julia> [1,2,3,4]
4-element Array{Int64,1}:
 1
 2
 3
 4

julia> [1,2,3,4].^2
4-element Array{Int64,1}:
  1
  4
  9
 16

In general, element-by-element operators are prefixed by "." so as to
disambiguate them from the more general linear algebraic operators that
expect to treat arrays as mathematical objects in their own right, rather
than collections of mathematical objects.
-E


On Mon, Jul 14, 2014 at 5:26 PM, <[email protected]> wrote:

> Hi Julia users,
> I am absolutely embarrassed to ask this question, but I have not been able
> to find the correct combination of query words to yield the desired answer
> in the documentation or Google. Anyhow, what function could I use to raise
> an array to a power?
>
> testarray = Int64[1,2,3,4]
> pow(testarray,2)
>
> or
>
> power(testarray,2)
>
> do not work.
>
> Thank you for your help.
>
> Regards,
> WX
>

Reply via email to