Skip to main content
Glama
by apetta

array_transform

Transform arrays for machine learning preprocessing and data normalization using L2 normalization, standardization, min-max scaling, or log transformation.

Instructions

Transform arrays for ML preprocessing and data normalization.

Transformations: - normalize: L2 normalization (unit vector) - standardize: Z-score (mean=0, std=1) - minmax_scale: Scale to [0,1] range - log_transform: Natural log transform

Examples:

L2 NORMALIZATION: data=[[3,4]], transform="normalize" Result: [[0.6,0.8]] (3²+4²=25, √25=5, 3/5=0.6, 4/5=0.8)

STANDARDIZATION (Z-SCORE): data=[[1,2],[3,4]], transform="standardize" Result: Values with mean=0, std=1

MIN-MAX SCALING: data=[[1,2],[3,4]], transform="minmax_scale" Result: [[0,0.33],[0.67,1]] (scaled to [0,1])

LOG TRANSFORM: data=[[1,10,100]], transform="log_transform" Result: [[0,2.3,4.6]] (natural log)

Input Schema

NameRequiredDescriptionDefault
contextNoOptional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification.
output_modeNoOutput format: full (default), compact, minimal, value, or final. See batch_execute tool for details.full
dataYes2D array to transform (e.g., [[1,2],[3,4]])
transformYesTransformation type
axisNoAxis: 0=column-wise, 1=row-wise, None=overall

Input Schema (JSON Schema)

{ "properties": { "axis": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Axis: 0=column-wise, 1=row-wise, None=overall" }, "context": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification." }, "data": { "description": "2D array to transform (e.g., [[1,2],[3,4]])", "items": { "items": { "type": "number" }, "type": "array" }, "type": "array" }, "output_mode": { "default": "full", "description": "Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details.", "enum": [ "full", "compact", "minimal", "value", "final" ], "type": "string" }, "transform": { "description": "Transformation type", "enum": [ "normalize", "standardize", "minmax_scale", "log_transform" ], "type": "string" } }, "required": [ "transform", "data" ], "type": "object" }

Implementation Reference

  • Full implementation of the array_transform tool, including decorator registration, input schema (data: List[List[float]], transform: Literal[...], axis: Optional[int]), and handler logic for normalize/standardize/minmax_scale/log_transform using NumPy with axis support.
    name="array_transform", description="""Transform arrays for ML preprocessing and data normalization. Transformations: - normalize: L2 normalization (unit vector) - standardize: Z-score (mean=0, std=1) - minmax_scale: Scale to [0,1] range - log_transform: Natural log transform Examples: L2 NORMALIZATION: data=[[3,4]], transform="normalize" Result: [[0.6,0.8]] (3²+4²=25, √25=5, 3/5=0.6, 4/5=0.8) STANDARDIZATION (Z-SCORE): data=[[1,2],[3,4]], transform="standardize" Result: Values with mean=0, std=1 MIN-MAX SCALING: data=[[1,2],[3,4]], transform="minmax_scale" Result: [[0,0.33],[0.67,1]] (scaled to [0,1]) LOG TRANSFORM: data=[[1,10,100]], transform="log_transform" Result: [[0,2.3,4.6]] (natural log)""", annotations=ToolAnnotations( title="Array Transformation", readOnlyHint=True, idempotentHint=True, ), ) async def array_transform( data: Annotated[ List[List[float]], Field(description="2D array to transform (e.g., [[1,2],[3,4]])") ], transform: Annotated[ Literal["normalize", "standardize", "minmax_scale", "log_transform"], Field(description="Transformation type"), ], axis: Annotated[ int | None, Field(description="Axis: 0=column-wise, 1=row-wise, None=overall") ] = None, ) -> str: """Transform arrays.""" try: arr = list_to_numpy(data) if transform == "normalize": # L2 normalization if axis is None: norm = np.linalg.norm(arr) result = (arr / norm if norm != 0 else arr).tolist() elif axis == 0: norms = np.linalg.norm(arr, axis=0, keepdims=True) result = (arr / np.where(norms != 0, norms, 1)).tolist() else: norms = np.linalg.norm(arr, axis=1, keepdims=True) result = (arr / np.where(norms != 0, norms, 1)).tolist() elif transform == "standardize": # Z-score standardization if axis is None: mean = np.mean(arr) std = np.std(arr, ddof=1) result = ((arr - mean) / std if std != 0 else arr - mean).tolist() elif axis == 0: mean = np.mean(arr, axis=0, keepdims=True) std = np.std(arr, axis=0, ddof=1, keepdims=True) result = ((arr - mean) / np.where(std != 0, std, 1)).tolist() else: mean = np.mean(arr, axis=1, keepdims=True) std = np.std(arr, axis=1, ddof=1, keepdims=True) result = ((arr - mean) / np.where(std != 0, std, 1)).tolist() elif transform == "minmax_scale": # Min-Max scaling to [0, 1] if axis is None: min_val = np.min(arr) max_val = np.max(arr) range_val = max_val - min_val result = ((arr - min_val) / range_val if range_val != 0 else arr - min_val).tolist() elif axis == 0: min_val = np.min(arr, axis=0, keepdims=True) max_val = np.max(arr, axis=0, keepdims=True) range_val = max_val - min_val result = ((arr - min_val) / np.where(range_val != 0, range_val, 1)).tolist() else: min_val = np.min(arr, axis=1, keepdims=True) max_val = np.max(arr, axis=1, keepdims=True) range_val = max_val - min_val result = ((arr - min_val) / np.where(range_val != 0, range_val, 1)).tolist() elif transform == "log_transform": # Natural log transform (handles negatives by using log1p) result = np.log1p(np.abs(arr) * np.sign(arr)).tolist() else: raise ValueError(f"Unknown transform: {transform}") return format_array_result(result, {"transform": transform, "axis": axis}) except Exception as e: raise ValueError(f"Transformation failed: {str(e)}")
  • Tool registration decorator @mcp.tool defining name, description, and annotations for array_transform.
    name="array_transform", description="""Transform arrays for ML preprocessing and data normalization. Transformations: - normalize: L2 normalization (unit vector) - standardize: Z-score (mean=0, std=1) - minmax_scale: Scale to [0,1] range - log_transform: Natural log transform Examples: L2 NORMALIZATION: data=[[3,4]], transform="normalize" Result: [[0.6,0.8]] (3²+4²=25, √25=5, 3/5=0.6, 4/5=0.8) STANDARDIZATION (Z-SCORE): data=[[1,2],[3,4]], transform="standardize" Result: Values with mean=0, std=1 MIN-MAX SCALING: data=[[1,2],[3,4]], transform="minmax_scale" Result: [[0,0.33],[0.67,1]] (scaled to [0,1]) LOG TRANSFORM: data=[[1,10,100]], transform="log_transform" Result: [[0,2.3,4.6]] (natural log)""", annotations=ToolAnnotations( title="Array Transformation", readOnlyHint=True, idempotentHint=True, ), )
  • Input schema defined via Annotated types and Field descriptions for data, transform, and axis parameters.
    data: Annotated[ List[List[float]], Field(description="2D array to transform (e.g., [[1,2],[3,4]])") ], transform: Annotated[ Literal["normalize", "standardize", "minmax_scale", "log_transform"], Field(description="Transformation type"), ], axis: Annotated[ int | None, Field(description="Axis: 0=column-wise, 1=row-wise, None=overall") ] = None, ) -> str:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/apetta/vibe-math-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server