def unit_vector(data, axis=None, out=None):
 if (out is None):
  data = numpy.array(data, dtype=numpy.float64, copy=True)
  if (data.ndim == 1):
   data /= math.sqrt(numpy.dot(data, data))
   return data
 else:
  if (out is not data):
   out[:] = numpy.array(data, copy=False)
  data = out
 length = numpy.atleast_1d(numpy.sum((data * data), axis))
 numpy.sqrt(length, length)
 if (axis is not None):
  length = numpy.expand_dims(length, axis)
 data /= length
 if (out is None):
  return data

def unit_vector ( data , axis = None , out = None ) : if ( out is None ) : data = numpy . array ( data , dtype = numpy . float64 , copy = True ) if ( data . ndim == 1 ) : data /= math . sqrt ( numpy . dot ( data , data ) ) return data else : if ( out is not data ) : out [ : ] = numpy . array ( data , copy = False ) data = out length = numpy . atleast_1d ( numpy . sum ( ( data * data ) , axis ) ) numpy . sqrt ( length , length ) if ( axis is not None ) : length = numpy . expand_dims ( length , axis ) data /= length if ( out is None ) : return data
return ndarray normalized by length .