Skip to content

Instantly share code, notes, and snippets.

@duhaime
Created March 12, 2019 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duhaime/56a47bf746ea95e86df00d145f8ad76c to your computer and use it in GitHub Desktop.
Save duhaime/56a47bf746ea95e86df00d145f8ad76c to your computer and use it in GitHub Desktop.
Frame-level diffs
##
# 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