5.12. Multidimensional arrays#

In the previous section, we learned how to access one element of a unidimensional array using indexing, and how to access multiple elements of a unidimensional array using slicing and filtering. We will now generalize this to multidimensional arrays. Through this tutorial, we will use these two sample arrays:

Sample array #1: Trajectory of a marker during three samples

The position of a marker is expressed by three coordinates (x, y, z), usually followed by a constant of 1. A trajectory is expressed as a series of positions. Therefore, we express the trajectory of a marker using:

  • Axis 0: sample

  • Axis 1: coordinate

_images/43d0e08b77dcc12e1247a64ab36f27e7776850b070cd690d4daef5838074c366.png
import numpy as np

position = np.array(
    [
        [0.497, 0.973, 0.010, 1.0],
        [0.528, 0.973, 0.017, 1.0],
        [0.589, 0.970, 0.025, 1.0],
    ]
)

position
array([[0.497, 0.973, 0.01 , 1.   ],
       [0.528, 0.973, 0.017, 1.   ],
       [0.589, 0.97 , 0.025, 1.   ]])

Sample array #2: Series of segment orientation during two samples

The orientation of a segment is expressed as a 4x4 homogeneous matrix. Therefore, we can express a series of orientations using:

  • Axis 0: sample

  • Axis 1: line of the homogeneous transform matrix

  • Axis 2: column of the homogeneous transform matrix

_images/7c0e9c7934f938d1a3bb38a4277dc7761f877bb5911658f6a34a2bc18db65ddd.png
orientation = np.array(
    [
        [
            [1.0, 0.0, 0.0, 0.0],
            [0.0, 1.0, 0.0, 0.0],
            [0.0, 0.0, 1.0, 0.0],
            [0.0, 0.0, 0.0, 1.0],
        ],
        [
            [1.0, 0.000, 0.000, 0.0],
            [0.0, 0.999, -0.017, 0.0],
            [0.0, 0.017, 0.999, 0.0],
            [0.0, 0.000, 0.000, 1.0],
        ],
    ]
)

orientation
array([[[ 1.   ,  0.   ,  0.   ,  0.   ],
        [ 0.   ,  1.   ,  0.   ,  0.   ],
        [ 0.   ,  0.   ,  1.   ,  0.   ],
        [ 0.   ,  0.   ,  0.   ,  1.   ]],

       [[ 1.   ,  0.   ,  0.   ,  0.   ],
        [ 0.   ,  0.999, -0.017,  0.   ],
        [ 0.   ,  0.017,  0.999,  0.   ],
        [ 0.   ,  0.   ,  0.   ,  1.   ]]])