Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I asked thisthis question a few days ago. The question is about producing moving/rolling windows of an array in Python as in the following example:

I asked this question a few days ago. The question is about producing moving/rolling windows of an array in Python as in the following example:

I asked this question a few days ago. The question is about producing moving/rolling windows of an array in Python as in the following example:

fixed typo
Source Link
r_31415
  • 137
  • 6
import numpy as np

def extend_image(image, steps=16):
    # Required number of rows
    required_rows = np.mod(image.shape[0], steps)
    # Required number of columns
    required_cols = np.mod(imgimage.shape[1], steps) 
    # Concatenate original array with rows filled with zeros 
    partial = np.concatenate((image, np.zeros((required_rows,image.shape[1])))) 
    # Concatenate partial array with columns filled with zeros
    extended = np.concatenate((partial, np.zeros((partial.shape[0], required_cols))), axis=1) 
    return extended
import numpy as np

def extend_image(image, steps=16):
    # Required number of rows
    required_rows = np.mod(image.shape[0], steps)
    # Required number of columns
    required_cols = np.mod(img.shape[1], steps) 
    # Concatenate original array with rows filled with zeros 
    partial = np.concatenate((image, np.zeros((required_rows,image.shape[1])))) 
    # Concatenate partial array with columns filled with zeros
    extended = np.concatenate((partial, np.zeros((partial.shape[0], required_cols))), axis=1) 
    return extended
import numpy as np

def extend_image(image, steps=16):
    # Required number of rows
    required_rows = np.mod(image.shape[0], steps)
    # Required number of columns
    required_cols = np.mod(image.shape[1], steps) 
    # Concatenate original array with rows filled with zeros 
    partial = np.concatenate((image, np.zeros((required_rows,image.shape[1])))) 
    # Concatenate partial array with columns filled with zeros
    extended = np.concatenate((partial, np.zeros((partial.shape[0], required_cols))), axis=1) 
    return extended
added a few comments
Source Link
r_31415
  • 137
  • 6
import numpy as np 

def extend_image(image, steps=16):
    # Required number of rows
    required_rows = np.mod(image.shape[0], steps)
    # Required number of columns
    required_cols = np.mod(img.shape[1], steps) 
    # Concatenate original array with rows filled with zeros 
    partial = np.concatenate((image, np.zeros((required_rows,image.shape[1])))) 
    # Concatenate partial array with columns filled with zeros
    extended = np.concatenate((partial, np.zeros((partial.shape[0], required_cols))), axis=1) 
    return extended
import numpy as np
def extend_image(image, steps=16):
    required_rows = np.mod(image.shape[0], steps)
    required_cols = np.mod(img.shape[1], steps)
    partial = np.concatenate((image, np.zeros((required_rows,image.shape[1]))))
    extended = np.concatenate((partial, np.zeros((partial.shape[0], required_cols))), axis=1)
    return extended
import numpy as np 

def extend_image(image, steps=16):
    # Required number of rows
    required_rows = np.mod(image.shape[0], steps)
    # Required number of columns
    required_cols = np.mod(img.shape[1], steps) 
    # Concatenate original array with rows filled with zeros 
    partial = np.concatenate((image, np.zeros((required_rows,image.shape[1])))) 
    # Concatenate partial array with columns filled with zeros
    extended = np.concatenate((partial, np.zeros((partial.shape[0], required_cols))), axis=1) 
    return extended
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Loading
Source Link
r_31415
  • 137
  • 6
Loading