code: def generate_neighbours_pattern(radius):
      """
      Generates pattern that defines neighbours
      within specified radius on the hexagon grid.
  
      Parameters
      ----------
      radius : int
  
      Returns
      -------
      array-like
          2d-array that has number of rows equal to number
          of columns equal to ``2 * radius + 1``
      """
      cache = generate_neighbours_pattern.cache
  
      if radius in cache:
          return cache[radius]
  
      size = 2 * radius + 1
      max_distance = radius + 1
      pattern = np.zeros((size, size))
  
      for i, width in enumerate(range(size - radius, size + 1)):
          start_point = radius - int(np.floor(width / 2))
          neighbour_range = slice(start_point, start_point + width)
  
          neighbour_distance = np.pad(
              array=(max_distance - i) * [max_distance - i],
              pad_width=i,
              mode="linear_ramp",
              end_values=max_distance,
          )
  
          pattern[i, neighbour_range] = neighbour_distance
          # every row in the pattern is mirror symmetric
          pattern[size - i - 1, neighbour_range] = neighbour_distance
  
      cache[radius] = pattern
      return pattern
  
file_path: neupy/neupy/algorithms/competitive/neighbours.py
imports: from __future__ import division
  import numpy
  from neupy.core.docs import shared_docs
label_desc: Use image node_id 5 for calling a global function with example usage: generate_neighbours_pattern(radius) and returns: pattern, cache