Help with converting Numpy einsum to Julia

julia> x = collect(reshape(0:2*3*4*5*4-1, (2,3,1,4,5,1,4))); # now this is an Array

julia> ismutable(x)
true

julia> x[1:5]'
1×5 Adjoint{Int64,Array{Int64,1}}:
 0  1  2  3  4

julia> @einsum y3[i,j,k,l] := x[i,j,1,k,l,1,k]; # as before, := makes a new array

julia> y3 .= rand.(Int8);

julia> y3[1:5]'
1×5 Adjoint{Int64,Array{Int64,1}}:
 126  -11  -65  83  93

julia> @einsum x[i,j,1,k,l,1,k] += y3[i,j,k,l]; # with = or += this alters x

julia> x[1:5]'
1×5 Adjoint{Int64,Array{Int64,1}}:
 126  -10  -63  86  97

These packages differ a little in what they allow, @ein only supports := I think.

1 Like