How can I initialize high order tensor in Julia?

Viewed 74

I would like to define n-th order tensor X in Julia.

When n is small, we can define i[1]×i[2]×…×[n] tensor as

X = rand(i[1],i[2],i[3])

or

X = Array{Float64, 3}(undef, i[1], i[2], i[3])

These examples are in case of n=3. But when n is large and list i is given, how can I define high order tensor??

EDIT

I found heuristics answer.

using TensorToolbox
i = [3,4,2,5,4,1,3]
X = diagt(i)

Is this best practice?

1 Answers

Maybe you are looking for this?

rand(i...)

or that?

Array{Float64}(undef, i...)
Related