# Array weighted average

`array-weighted-average` · version 1.0.0 · Other utilities · free, no key needed

Compute an exact weighted mean of value and weight arrays and return one rounded decimal string.

**Use when you need to: weighted average arrays · weighted mean of values with weights · calculate weighted arithmetic mean.**

## Decide before calling

Read the [versioned contract](/v1/tools/array-weighted-average/versions/1.0.0) and the supported scope below. Reuse `array-weighted-average@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `array-weighted-average@1.0.0` for weighted average arrays. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- weighted average arrays
- weighted mean of values with weights
- calculate weighted arithmetic mean
- average numbers using weights
- exact decimal weighted average
- combine scores with numeric weights

## Not supported

- negative statistical weights
- streaming or grouped averages

## Behavior

- Uses sum(weight * value) / sum(weight); negative weights are rejected and zero total weight is not computable.
- Parses finite JSON numbers through their JSON decimal spelling, computes rationally, then rounds once using IEEE 754-2019 section 4.3.
- half_up rounds ties away from zero (for example, -2.5 rounds to -3 at zero decimal places).

## Input

- `values` (array of string or number, required): min items 1; max items 256
- `weights` (array of string or number, required): min items 1; max items 256
- `decimal_places` (integer, required): min 0; max 18
- `rounding_mode` (one of "half_even", "half_up", "toward_zero", "toward_positive", "toward_negative", required)

## Output

- `result` (string, required)
- `standard_version` (constant "IEEE 754-2019 section 4.3", required)

## Limits

- max input bytes: 32768
- max items: 256
- max decimal chars: 70
- max total decimal chars: 4096
- max digits: 64
- max exponent magnitude: 100
- max decimal places: 18
- max iterations: 256
- max output bytes: 32768

## Example

Request input:

```json
{
  "values": [
    "10",
    "20"
  ],
  "weights": [
    "1",
    "3"
  ],
  "decimal_places": 2,
  "rounding_mode": "half_even"
}
```

Response:

```json
{
  "result": {
    "result": "17.50",
    "standard_version": "IEEE 754-2019 section 4.3"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "array-weighted-average",
  "version": "1.0.0",
  "input": {
    "values": [
      "10",
      "20"
    ],
    "weights": [
      "1",
      "3"
    ],
    "decimal_places": 2,
    "rounding_mode": "half_even"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/array-weighted-average/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"values":["10","20"],"weights":["1","3"],"decimal_places":2,"rounding_mode":"half_even"}'
```

The machine-readable contract is at [/v1/tools/array-weighted-average/versions/1.0.0](/v1/tools/array-weighted-average/versions/1.0.0).

### CLI

```sh
node cli.mjs run array-weighted-average 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Stats describe exact](/tools/stats-describe-exact): Return exact descriptive statistics and requested-precision standard deviations for decimal strings.
- [Stats histogram](/tools/stats-histogram): Count decimal-string values in caller-supplied fixed bins and return below- and above-range totals.
- [Array duplicates find](/tools/array-duplicates-find): List duplicated JSON values with counts and first indexes, preserving first-seen order.
- [Array set intersection](/tools/array-set-intersection): Return unique left-array values also in the right array, in first-seen order.
- [Polygon measures compute](/tools/polygon-measures-compute): Compute exact signed double-area, area, orientation, and squared edge lengths for a rational simple polygon.
- [Stats percentile](/tools/stats-percentile): Compute an exact percentile from decimal strings using a named Hyndman-Fan type 1 through 9.
