Created
March 12, 2019 01:32
-
-
Save duhaime/56a47bf746ea95e86df00d145f8ad76c to your computer and use it in GitHub Desktop.
Frame-level diffs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Example cell showing transformation logic | |
## | |
# sample initial conditions for array with 3 verts, 2 time stamps, 3 dims | |
a = np.array([ | |
[ # vert | |
[3,3,3], # vert 0 time 0 | |
[7,7,7] | |
], | |
[ | |
[9,9,9], # vert 0 time 1 | |
[11,11,11] | |
], | |
[ | |
[5,5,5], # vert 0 time 2 | |
[11,11,11] | |
] | |
]) | |
# time-stamp level offsets; shape = a.shape[0], a.shape[1]-1, a.shape[2] | |
b = np.diff(a, axis=1) | |
# to find the final positions, take starting positions + frame by frame offsets | |
initial = np.expand_dims( a[:,0,:], axis=1 ) | |
sums = np.cumsum(b, axis=1) | |
cumsums = np.add(initial, sums) | |
frames = np.concatenate([initial, cumsums], axis=1) | |
np.all(frames == a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment