code: def asarray_ndim(a, *ndims, **kwargs):
      
      allow_none = kwargs.pop('allow_none', False)
      kwargs.setdefault('copy', False)
      if a is None and allow_none:
          return None
      a = np.array(a, **kwargs)
      if a.ndim not in ndims:
          if len(ndims) > 1:
              expect_str = 'one of %s' % str(ndims)
          else:
              # noinspection PyUnresolvedReferences
              expect_str = '%s' % ndims[0]
          raise TypeError('bad number of dimensions: expected %s; found %s' %
                          (expect_str, a.ndim))
      return a
docs: Ensure numpy array.
  
      Parameters
      ----------
      a : array_like
      *ndims : int, optional
          Allowed values for number of dimensions.
      **kwargs
          Passed through to :func:`numpy.array`.
  
      Returns
      -------
      a : numpy.ndarray