code: def blocks(seq, size=None, hop=None, padval=0.):
    
    # Initialization
    res = deque(maxlen=size) # Circular queue
    idx = 0
    last_idx = size - 1
    if hop is None:
      hop = size
    reinit_idx = size - hop
  
    # Yields each block, keeping last values when needed
    if hop <= size:
      for el in seq:
        res.append(el)
        if idx == last_idx:
          yield res
          idx = reinit_idx
        else:
          idx += 1
  
    # Yields each block and skips (loses) data due to hop > size
    else:
      for el in seq:
        if idx < 0: # Skips data
          idx += 1
        else:
          res.append(el)
          if idx == last_idx:
            yield res
            #res = dtype()
            idx = size-hop
          else:
            idx += 1
  
    # Padding to finish
    if idx > max(size-hop, 0):
      for _ in xrange(idx,size):
        res.append(padval)
      yield res
docs: General iterable blockenizer.
  
    Generator that gets ``size`` elements from ``seq``, and outputs them in a
    collections.deque (mutable circular queue) sequence container. Next output
    starts ``hop`` elements after the first element in last output block. Last
    block may be appended with ``padval``, if needed to get the desired size.
  
    The ``seq`` can have hybrid / hetherogeneous data, it just need to be an
    iterable. You can use other type content as padval (e.g. None) to help
    segregate the padding at the end, if desired.
  
    Note
    ----
    When hop is less than size, changing the returned contents will keep the
    new changed value in the next yielded container.