Skip to content

Instantly share code, notes, and snippets.

@nv1t
Last active October 26, 2019 15:10
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 nv1t/8a5975c2da3a8cb00d44f5f3a80246b1 to your computer and use it in GitHub Desktop.
Save nv1t/8a5975c2da3a8cb00d44f5f3a80246b1 to your computer and use it in GitHub Desktop.
padding of smaller array to match bigger one with values
# 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