Is there a way to create a new array of squared elements using the @tullio
einsum functionality?
My first attempt was:
@tullio M[x, y, z] := A[x, y, z] * A[x, y, z]
But this doesn't seem to work like I thought it would
I guess my question is can I do A .^ 2
using Tullio and einsum notation?
What did you expect for that to do? It's the same as A .^ 2
for me.
julia> A = collect(reshape(1:(2^3), 2, 2, 2))
2×2×2 Array{Int64, 3}:
[:, :, 1] =
1 3
2 4
[:, :, 2] =
5 7
6 8
julia> using Tullio
julia> @tullio M[x, y, z] := A[x, y, z] * A[x, y, z]
2×2×2 Array{Int64, 3}:
[:, :, 1] =
1 9
4 16
[:, :, 2] =
25 49
36 64
julia> M == A .^ 2
true
@tullio M[i,j,k] := A[i,j,k]^2
works just as well
Hmm, I cannot recreate the error so I am not sure what I was doing wrong originally. Thank you both though, this works
Last updated: Nov 22 2024 at 04:41 UTC