code: def norm_squared(x, Mx=None, inner_product=ip_euclid):
      '''Compute the norm^2 w.r.t. to a given scalar product.'''
      assert(len(x.shape) == 2)
      if Mx is None:
          rho = inner_product(x, x)
      else:
          assert(len(Mx.shape) == 2)
          rho = inner_product(x, Mx)
  
      if rho.shape == (1, 1):
          if abs(rho[0, 0].imag) > abs(rho[0, 0])*1e-10 or rho[0, 0].real < 0.0:
              raise InnerProductError(('<x,Mx> = %g. Is the inner product '
                                       'indefinite?') % rho[0, 0])
  
      return numpy.linalg.norm(rho, 2f norm_squared(x, Mx=None, inner_product=ip_euclid):
      '''Compute the norm^2 w.r.t. to a given scalar product.'''
      assert(len(x.shape) == 2)
      if Mx is None:
          rho = inner_product(x, x)
      else:
          assert(len(Mx.shape) == 2)
          rho = inner_product(x, Mx)
  
      if rho.shape == (1, 1):
          if abs(rho[0, 0].imag) > abs(rho[0, 0])*1e-10 or rho[0, 0].real < 0.0:
              raise InnerProductError(('<x,Mx> = %g. Is the inner product '
                                       'indefinite?') % rho[0, 0])
  
      return numpy.linalg.norm(rho, 2)
docs: Compute the norm^2 w.r.t. to a given scalar product.