1

I'm have data of multiple points coordinates like this:

Frame x1 y1 z1 x2 y2 z2 xn yn zn
1 0.1 0.2 0. 3 0.4 0.5 0.6 0.7 0.8 0.9
2 0.2 0.2 0. 3 0.4 0.5 0.6 0.7 0.8 0.9

And i want to convert it to a numpy array so i can plot the points in a surface, so I want to convert each "frame" row to this:

P = [[x1,y1,z1],[x2,y2,z2],[xn,yn,zn]]

and this:

V = [[x1,y1],[x2,y2],[xn,yn]]

Anybody knows how? Thanks

3
  • 1
    Can you make an explicit expected output that matches your input/table (DataFrame?) ? Commented Apr 30, 2023 at 19:23
  • 1
    what you call "frames" look like rows of a DataFrame, which would actually mean Series Commented Apr 30, 2023 at 19:36
  • 1
    yeah sorry, I wrote frame because it's motion capture data and in the original data set it's called that way Commented Apr 30, 2023 at 20:53

1 Answer 1

4

The exact shape of the output should be clarified, but the general logic will be to reshape:

(df.set_index('Frame')
   .to_numpy()
   .reshape((len(df), -1, 3))
)

Output:

array([[[0.1, 0.2, 0.3],   # x1, y1, z1  # first row
        [0.4, 0.5, 0.6],   # x2, y2, z2
        [0.7, 0.8, 0.9]],  # x3, y3, z3

       [[0.2, 0.2, 0.3],   # x1, y1, z1  # second row
        [0.4, 0.5, 0.6],   # x2, y2, z2
        [0.7, 0.8, 0.9]]]) # x3, y3, z3
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry if I wasn't clear but that is exactly what i was looking for, only I want a different array for each row, but i think i can work it out with your answer. Thank you so much!
Each subarray is also an array. Assuming a the output of my command you can use a[0] for the first. You can also convert all to a list: list(a) ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.