Organize the output of a mathematical model

Hello I have find a matrix q[j,i,k] at the end of my work, it represent the quantity of product k that should be ordered by client i from the plant j , I want to organize this output in a table in the row I find the plants and columns the customers and products to facilitate the interpretation of the results

Hi there!

Since this is your first post, you might want to start by reading: Please read: make it easier to help you

At the moment this is a little too generic of a question.

If you can post a small reproducible example with the (simplified) code of what you currently have, then people should be able to help, but this might be a good starting point:

using DataFrames
client, plant, product, amount = [], [], [], []
for j in 1:J
    for i in 1:I
        for k in 1:K
            push!(client, i)
            push!(plant, j)
            push!(product, k)
            push!(amount, q[j, i, k]
        end
    end
end
DataFrame(
    client = client,
    plant = plant,
    product = product,
    amount = amount,
)

Here are some other links:

1 Like

Not sure if understood alright, but FWIW:

using DataFrames

# INPUT 3D-ARRAY DATA
n1, n2, n3 = 2, 3, 4
q = round.(Int64, 100*rand(1:10, n1, n2, n3))

# CREATE 2D DATAFRAME
ix = Iterators.product(1:n1, 1:n2, 1:n3)
df = rename!(DataFrame(ix), [:client, :plant, :product])
df.quantity = reshape(q, n1*n2*n3)
df
2 Likes

thank you odow for the remark and the answer
I tried the code that you gave me and it answers what I was looking for

1 Like

thank you rafael

1 Like