Creating matrix from data input

Hi!
What would be the most effective way to do the following:

Given a certain data input (two lists with one number each) I need to create this table below.
Logic is simple, every time a certain number appears, it adds +1 to the respective column

Is it better with matrices, or with data trees?
Thanks in advance!

You can have a flat list and instead of using a 1d index you can use a 2d index and convert it to 1d and viceversa to use the list components. If i and j are the indices in 2d, U the number of columns, and index the index in 1d, you can convert it using:

index = i + j * U

and viceversa:

i = index % U
j = round(index / U)

1 Like

Thanks for the idea! I can see this could work…I’d love to hear other inputs regarding how to approach this situations though

A Matrix is more suitable to visualize the results.

I have a “similar” thingy in C#: pay attention to the way used in order to visual “map” a Matrix to some Tree (the demo graph, that is). Reason is that the Matrix is top left to right while a Tree (in most of cases) is bottom left to right (if this makes any sense).

Matrix_RndNum_V1.gh (120.3 KB)

So replace the internal demo with your stuff (or at least add an option) and off you go.

Thing is…I still can’t figure out how to generate the internal data of the matrix (or the 1d list) where the N row is the (N-1) row plus the input data…

It doesn’t seem so simple, detail it.

I put the table for visual reference.
I have 10 columns, labelled from 0 to 9. On row 0, all values are 0
On row 1, values from data input are 7 and 4. So it adds +1 to the column 7 and 4.
On row 2, values are 4 and 1. It adds +1 to the column 4 and 1.

In general, if i=rows and j= columns --> Cell [i,j] = Cell [i-1,j] + 1 (if input data [i] = j).

I guess I could transform input data into a [1,10] vector with 1s and 0s to work more easily…

Emm…


Creating matrix from data input.gh (12.8 KB)

Oh my!
Thanks a lot…gotta take a few minutes to understand this piece by piece, but it seems perfect.

Everytime I feel I’m getting the hand on GH, these solutions come up to show me I’m still a baby =D