1

I am in the process of collecting 3D-coordinates of multiple key points of one person's or multiple people's body over time. This data needs to be collected in one data set. This basically leads to an input for each frame consisting of one or multiple 19x3 matrices. The data set structure is supposed to look as following:

enter image description here

I am really struggling to wrap my head around how to loop all the data in one data set. As the data is generated during runtime, I cannot set-up the size of outer layer in advance. All my attempts so far to create 3D/4D arrays led to a misalignment of dimensions.

how to approach such problem?

1
  • Make a list of the data, concatenate it how you want later. Commented Jul 20, 2021 at 22:08

3 Answers 3

1

You have N frames, with N indeterminate, and each frame containing a pair of (19, 3) matrices. You can pre-allocate the frame you are currently working on:

frame = np.full((2, 19, 3), np.nan)

Filling with NaNs makes it easy to find unused matrices later. When you've collected a frame, append it to a list:

frames = []
...
frames.append(frame)  # Probably in a loop somewhere

Once you're done, concatenate into an array of shape (N, 2, 19, 3):

frames = np.stack(frames, axis=0)

The result can be indexed as (frame, matrix, row, col), where sometimes matrix == 1 is unfilled.

Sign up to request clarification or add additional context in comments.

1 Comment

That's a really good and easy to follow suggestion. Thanks for your time!
1

If you know the max number of 19x3 matrices in each frame, then you could set up the outer size and put empty matrices (or matrices of 0) where you don't have data. I think you might want to use pandas dataframe and take advantage of the indexing to make it easier to access your data later on.

1 Comment

Yeah that is a good idea! Would definitely facilitate things. However, on the other hand it leads to a lot of empty matrices. I'll take a look into it, thanks.
0

My final solution based on Mad Physicist's answer:

global dataFrame
dataFrame = []
#dataframe containing the entire coordinates table 
#The dataFrame can ce accessed as following: 
#dataFrame[#ofFrame][IdInFrame][limbNumber][Coordinate(x,y,z)]

def takeCoordinates():
    global dataFrame
    frame = np.full((2, 19, 3), np.nan)
    xRow, xCol = x.shape
    for n in range(xRow):
        coordArray = np.empty((0, 3), int)
        for m in range(xCol):
            coordArray = np.append(coordArray, np.array([[x[n, m], y[n, m], z[n, m]]]), axis=0)
        frame = np.insert(frame,n,coordArray,axis=0)
    dataFrame.append(frame)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.