Last active
October 26, 2019 15:10
-
-
Save nv1t/8a5975c2da3a8cb00d44f5f3a80246b1 to your computer and use it in GitHub Desktop.
padding of smaller array to match bigger one with values
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
# output: | |
# [2.88, 2.88, 2.88, 2.88, 3.2, 3.2, 3.2, 3.2, 3.2, 3.52] | |
# [2.88, 2.88, 2.88, 3.2, 3.2, 3.2, 3.2, 3.52] | |
# [2.88, 2.88, 2.88, 0, 3.2, 3.2, 3.2, 3.2, 0, 3.52] | |
a = [2.88,2.88,2.88,2.88,3.2,3.2,3.2,3.2,3.2,3.52] | |
b = [2.88,2.88,2.88,3.2,3.2,3.2,3.2,3.52] | |
def zero_pad_gen(a, b, _sentinel=object()): | |
a = iter(a) | |
nexta = next(a, _sentinel) | |
for bval in b: | |
if nexta is _sentinel or bval < nexta: | |
yield 0 | |
else: | |
yield nexta | |
nexta = next(a, _sentinel) | |
print(a) | |
print(b) | |
print(list(zero_pad_gen(b,a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment