docstr: Helper function, implementing pool_nd in pure numpy
docstr_tok: ["Helper","function",",","implementing","pool_nd","in","pure","numpy"]
code: def numpy_max_pool_nd(input, ws, ignore_border=False, mode="max"):
      """Helper function, implementing pool_nd in pure numpy"""
      if len(input.shape) < len(ws):
          raise NotImplementedError(
              "input should have at least %s dim,"
              " shape is %s" % (str(ws), str(input.shape))
          )
      nd = len(ws)
      si = [0] * nd
      if not ignore_border:
          for i in range(nd):
              if input.shape[-nd + i] % ws[i]:
                  si[i] += 1
      out_shp = list(input.shape[:-nd])
      for i in range(nd):
          out_shp.append(input.shape[-nd + i] // ws[i] + si[i])
      output_val = np.zeros(out_shp)
      func = np.max
      if mode == "sum":
          func = np.sum
      elif mode != "max":
          func = np.average
  
      for l in np.ndindex(*input.shape[:-nd]):
          for r in np.ndindex(*output_val.shape[-nd:]):
              patch = input[l][
                  tuple(
                      slice(r[i] * ws[i], (r[i] + 1) * ws[i])
                      for i in range(nd)
                  )
              ]
              output_val[l][r] = func(patch)
      return output_val
  
imports: from __future__ import absolute_import, print_function, division
  from nose.plugins.skip import SkipTest
  from parameterized import parameterized
  from itertools import product
  import os
  import unittest
  from six import reraise
  from six.moves import cPickle
  import six.moves.builtins
  import sys
  import numpy
  import theano
  import theano.tensor
  from theano.tests import unittest_tools
  from theano.tensor.signal.pool import Pool, pool_2d, pool_3d, MaxPoolGrad, AveragePoolGrad, max_pool_2d_same_size, DownsampleFactorMaxGradGrad
  from theano import function
label_desc: Use image node_id 3 for calling the TestDownsampleFactorMax obj's underlying member method code with example usage: obj.numpy_max_pool_nd(input, ws, ignore_border, mode) and returns: output_val