math.vector
Module math.vector
Declarations
Definitions
ballerina/math.vector Ballerina library
Functions
cosineSimilarity
Calculates the cosine similarity between two float vectors.
float[] v1 = [1.0, 2.0, 3.0]; float[] v2 = [4.0, 5.0, 6.0]; cosineSimilarity(v1, v2) ⇒ 0.9746318461970762
Return Type
- float - the cosine similarity between the given two vectors
dotProduct
Calculates the dot product of two float vectors.
float[] v1 = [1.0, 2.0, 3.0]; float[] v2 = [4.0, 5.0, 6.0]; dotProduct(v1, v2) ⇒ 32.0
Return Type
- float - the dot product of the given two vectors
euclideanDistance
Calculates the Euclidean distance between two float vectors.
float[] v1 = [1.0, 2.0, 3.0]; float[] v2 = [4.0, 5.0, 6.0]; euclideanDistance(v1, v2) ⇒ 5.196152422706632
Return Type
- float - the Euclidean distance between the given two vectors
manhattanDistance
Calculates the Manhattan distance between two float vectors.
float[] v1 = [1.0, 2.0, 3.0]; float[] v2 = [4.0, 5.0, 6.0]; manhattanDistance(v1, v2) ⇒ 9.0
Return Type
- float - the Manhattan distance between the given two vectors
vectorNorm
Calculates the L1 and L2 norm of a float vector.
float[] v = [1.0, 2.0, 3.0]; vectorNorm(v, vector:L2) ⇒ 3.7416573867739413 vectorNorm(v, vector:L1) ⇒ 6.0
Parameters
- v float[] - float vector to operate on
- norm NormType - norm type to calculate out of [L1, L2]
Return Type
- float - the L1 or L2 norm of the given float vector
Enums
math.vector: NormType
An enum containing the supported norm types. L1 - L1 norm which is the sum of the absolute values of the vector elements L2 - L2 norm which is the square root of the sum of the squared vector elements.
Members
Import
import ballerina/math.vector;Metadata
Released date: 11 months ago
Version: 1.1.0
License: Apache-2.0
Compatibility
Platform: any
Ballerina version: 2201.11.0-20241209-162400-0c015833
GraalVM compatible: Yes
Pull count
Total: 0
Current verison: 0
Weekly downloads
Keywords
math
vector
distance
Contributors