title: Could not broadcast input array from shape (2,2,3) into shape (224,224,3) - extracting blocks from NumPy Array
body: <p>I'm trying to create several patches with a specified size - 1800, 224, 224, 3 - from a raster image (1, 4646, 4827, 3) through the following code:</p>
  <pre><code>import numpy as np
  
  image = images_final
  tiles = np.zeros((1400, 224, 224, 3))
  
  c = 0
  
  for i in range(0, image.shape[1], 2):  
  
  for j in range(0, image.shape[2], 2):
  
      tiles[c] = image[:, i:i+2, j:j+2]
      c += 1
  </code></pre>
  <p>However, I keep getting the following message: ValueError: could not broadcast input array from shape (2,2,3) into shape (224,224,3).</p>
  <p>I also tried the following code:</p>
  <pre><code>def for_loop_split(image: np.ndarray, kernel_size: tuple):
  img_height, img_width, channels = image.shape
  tile_height, tile_width = kernel_size
  
  tiled_array = np.zeros ((img_height // tile_height,
                         img_width // tile_width,
                         tile_height,
                         tile_width,
                         channels))
    y = x = 0
    for i in range(0, img_height, tile_height):
    for j in range (0,img_width,tile_width):
    tiled_array[y][x] = image[i:i+tile_height,
                              j:j+tile_width,
                              :channels]
    x += 1
    y += 1
    x = 0 
    return tiled_array
  
   patches = stride_split(img,tilesize)
  </code></pre>
  <p>BUT the output is (20, 21, 224, 224, 3), and I need it to be <em>number of patches</em> x 224 x 224 x 3, the last corresponding to the channels of the raster.</p>
  <p>I know that there are several solutions for the same error, but they are not applicable for my specific issue. Could anyone help me with that?</p>