Centroid

Calculates the centroid of an array of vectors

Overview

This node calculates the centroid (geometric center) of an array of vectors. The centroid is computed by averaging each corresponding component across all input vectors, resulting in a single vector representing their center point.

Common scenarios where this node is useful include:

  • Data analysis tasks requiring the average position of multiple points in multi-dimensional space.
  • Machine learning preprocessing to find mean feature vectors.
  • Geospatial computations to find the central location from multiple coordinates.
  • Any workflow needing to summarize or reduce multiple vector inputs into one representative vector.

For example, given vectors [[1,2,3],[4,5,6],[7,8,9]], the node outputs the centroid [4,5,6].

Properties

Name Meaning
Array of Vectors An array of numeric vectors (arrays) to calculate the centroid from. Example: [[1,2,3],[4,5,6],[7,8,9]]

Output

The output contains a single JSON object with one field:

  • centroid: An array representing the centroid vector calculated by averaging each dimension across all input vectors.

Example output JSON:

{
  "centroid": [4, 5, 6]
}

No binary data output is produced by this node.

Dependencies

  • No external services or API keys are required.
  • This node operates purely on input data provided either directly via the property or from previous nodes in the workflow.

Troubleshooting

  • Invalid vector array format: If the input is not a valid JSON array of arrays, the node throws an error stating the format is invalid. Ensure the input is a proper JSON array of numeric arrays.
  • Empty or missing input: The node requires at least one vector; otherwise, it throws an error indicating a valid array must be provided.
  • Inconsistent vector dimensions: All vectors must have the same length/dimension. If they differ, an error is thrown.
  • Parsing errors: If the input is a string but not valid JSON, parsing will fail and throw an error.

To resolve these issues, verify that the input is a well-formed JSON array of equal-length numeric arrays.

Links and References

Discussion