normalize_vectors: Normalize vectors to have length 1

Description Usage Arguments Value Author(s) Examples

View source: R/normalize-vectors.R

Description

Takes in one or more vectors and normalizes their lengths to 1.

Usage

1

Arguments

vectors

A n x d matrix or data frame that contains one vector per row, and one column per dimension.

Value

The return value is of the same type as vectors, and contains the normalized vectors.

Author(s)

Mathias Isaksen mathiasleanderi@gmail.com

Examples

1
2
3
4
5
6
7
8
9
set.seed(123)
# Generate random 2D vectors
vectors = matrix(runif(200, -1, 1), ncol = 2)
# The lengths are varied
summary(sqrt(rowSums(vectors^2)))
# Normalize vectors
normalized.vectors = normalize_vectors(vectors)
# The lengths are all equal to 1
summary(sqrt(rowSums(normalized.vectors^2)))

mathiasisaksen/artKIT documentation built on Dec. 21, 2021, 2:52 p.m.