Ensure that the vector or vectors have unit norm
16331
def safe_unit_norm(a):
    
    if 1 == len(a.shape):
        n = np.linalg.norm(a)
        if n:
            return a / n
        return a

    norm = np.sum(np.abs(a) ** 2, axis=-1) ** (1. / 2)

    # Dividing by a norm of zero will cause a warning to be issued. Set those
    # values to another number. It doesn't matter what, since we'll be dividing
    # a vector of zeros by the number, and 0 / N always equals 0.
    norm[norm == 0] = -1e12
    return a / norm[:, np.newaxis]
1334466
function (t) {
        var p = someVectorAt(this.shape, t, true);
        return vec2.normalize(p, p);
    }
880817
def _normalise(self):
        
        if not self.is_unit():
            n = self.norm
            if n > 0:
                self.q = self.q / n
867607
private static void check(Vector a, Vector b) {
        if (a.length() != b.length())
            throw new IllegalArgumentException(
                    "input vector lengths do not match");
    }
684400
def normalize(x:TensorImage, mean:FloatTensor,std:FloatTensor)->TensorImage:
    ""
    return (x-mean[...,None,None]) / std[...,None,None]
149799
function norm(n, X, incx, offx) {
    // Euclidean norm
    // LAPACK: DNRM2

    if (n === 0.0) {
      return Math.abs(n);
    }

    var scale = 0.0;
    var ssq = 1.0;
    for (var i = 0; i < n; ++i) {
      var xi = X[offx + incx*i];
      if (xi !== 0.0) {
        var absxi = Math.abs(xi);
        if (scale < absxi) {
          var z = scale / absxi;
          ssq = 1.0 + ssq * (z * z);
          scale = absxi;
        } else {
          var z = absxi / scale;
          ssq = ssq + z * z;
        }
      }
    }
    return scale * Math.sqrt(ssq);
  }
1054600
def _norm(self, value):
        """"""
        self._bit_value = value * self._unit_value
        self._byte_value = self._bit_value / 8.0
613211
def normframe(I: np.ndarray, Clim: tuple) -> np.ndarray:
    
    Vmin = Clim[0]
    Vmax = Clim[1]

    # stretch to [0,1]
    return (I.astype(np.float32).clip(Vmin, Vmax) - Vmin) / (Vmax - Vmin)
1235813
def normalize(self, df=None, norm_type='zscore', axis='row', keep_orig=False):
    '''
    
    '''
    normalize_fun.run_norm(self, df, norm_type, axis, keep_orig)
576926
function enforceVectorDtype(array, dtype) {
  validateDtype(dtype);
  var coerceFunc = COERCE_FUNC[dtype];

  // Coerce all elements to dtype
  for (var i = 0; i < array.length; i++) {
    array[i] = coerceFunc(array[i]);
  }

  // Construct vector
  return newVector(array, dtype);
}
286623
def _norm_cmap(values, cmap, normalize, cm, vmin=None, vmax=None):
    

    mn = min(values) if vmin is None else vmin
    mx = max(values) if vmax is None else vmax
    norm = normalize(vmin=mn, vmax=mx)
    n_cmap = cm.ScalarMappable(norm=norm, cmap=cmap)
    return n_cmap
585555
def _check_r(self, r):
        """"""
        if abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \
            abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \
            abs(np.dot(r[:, 0], r[:, 0]) - 1) > eps or \
            np.dot(r[:, 0], r[:, 1]) > eps or \
            np.dot(r[:, 1], r[:, 2]) > eps or \
            np.dot(r[:, 2], r[:, 0]) > eps:
            raise ValueError("The rotation matrix is significantly non-orthonormal.")
283850
def normalize_std_array(vector):
  """"""

  # Initializes variables
  length = 1
  n_samples = len(vector)
  mean = numpy.ndarray((length,), 'float64')
  std = numpy.ndarray((length,), 'float64')
  mean.fill(0)
  std.fill(0)

  # Computes mean and variance
  for array in vector:
    x = array.astype('float64')
    mean += x
    std += (x ** 2)

  mean /= n_samples
  std /= n_samples
  std -= (mean ** 2)
  std = std ** 0.5
  arrayset = numpy.ndarray(shape=(n_samples,mean.shape[0]), dtype=numpy.float64)

  for i in range (0, n_samples):
    arrayset[i,:] = (vector[i]-mean) / std
  return arrayset
514454
def reduce_vectors(a, b):
    
    if np.dot(a, b) < 0:
        return reduce_vectors(a, -b)

    if fast_norm(a) > fast_norm(b):
        return reduce_vectors(b, a)

    if fast_norm(b) > fast_norm(np.add(b, a)):
        return reduce_vectors(a, np.add(b, a))

    if fast_norm(b) > fast_norm(np.subtract(b, a)):
        return reduce_vectors(a, np.subtract(b, a))

    return [a, b]
213
public static void checkSvdMatrixSize(DMatrixRMaj U, boolean tranU, DMatrixRMaj W, DMatrixRMaj V, boolean tranV ) {
        int numSingular = Math.min(W.numRows,W.numCols);
        boolean compact = W.numRows == W.numCols;

        if( compact ) {
            if( U != null ) {
                if( tranU && U.numRows != numSingular )
                    throw new IllegalArgumentException("Unexpected size of matrix U");
                else if( !tranU && U.numCols != numSingular )
                    throw new IllegalArgumentException("Unexpected size of matrix U");
            }

            if( V != null ) {
            if( tranV && V.numRows != numSingular )
                throw new IllegalArgumentException("Unexpected size of matrix V");
            else if( !tranV && V.numCols != numSingular )
                throw new IllegalArgumentException("Unexpected size of matrix V");
            }
        } else {
            if( U != null && U.numRows != U.numCols )
                throw new IllegalArgumentException("Unexpected size of matrix U");
            if( V != null && V.numRows != V.numCols )
                throw new IllegalArgumentException("Unexpected size of matrix V");
            if( U != null && U.numRows != W.numRows )
                throw new IllegalArgumentException("Unexpected size of W");
            if( V != null && V.numRows != W.numCols )
                throw new IllegalArgumentException("Unexpected size of W");
        }
    }
742312
def proper(self,x):
        """"""
        x[x < 0] = self.max_fit
        x[np.isnan(x)] = self.max_fit
        x[np.isinf(x)] = self.max_fit
        return x
1328627
def vector_normalize(mat, max_vec_norm=1.):
    
    assert mat.flags.c_contiguous
    n, m = mat.shape

    vector_normalize_kernel.prepared_call(
        (m, 1, 1), (32, 1, 1),
        mat.gpudata,
        np.float32(max_vec_norm),
        np.int32(m),
        np.int32(n))