Skip to content

Instantly share code, notes, and snippets.

View schlameel's full-sized avatar

Schlameel schlameel

  • US
View GitHub Profile
@schlameel
schlameel / interleave.py
Last active July 24, 2020 18:46
Interleave data using numpy
import numpy as np
arr1 = np.zeros(100)
arr2 = np.ones(100)
arr_tuple = (arr1, arr2)
interleaved = np.vstack(arr_tuple).reshape((-1,), order='F')
@schlameel
schlameel / deinterleave.py
Last active November 8, 2023 00:10
De-interleave data using numpy
import numpy as np
CHANNEL_COUNT = 2
frames = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1])
deinterleaved = [frames[idx::CHANNEL_COUNT] for idx in range(CHANNEL_COUNT)]
print(deinterleaved[0])
# prints "[0 0 0 0 0 0 0 0 0 0]"
print(deinterleaved[1])
# prints "[1 1 1 1 1 1 1 1 1 1]"