Skip to content

Instantly share code, notes, and snippets.

@RicherMans
Last active June 12, 2019 08:15
Show Gist options
  • Save RicherMans/6ce6a90c328dd6470f579552cc28e4d2 to your computer and use it in GitHub Desktop.
Save RicherMans/6ce6a90c328dd6470f579552cc28e4d2 to your computer and use it in GitHub Desktop.
Interwaves two arrays given a specific ratio of array1 to array2, Ratio can also be float
def interweave(ratio, arr1, arr2):
combined_length = len(arr1) + len(arr2)
index_array = np.arange(combined_length)
take_array = (ratio * np.arange(0, len(arr1))).round().astype(int)
take_binary = np.zeros_like(index_array).astype(bool)
take_binary[take_array] = 1
index_array[take_binary] = arr1
index_array[~take_binary] = arr2
return index_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment