Statistics Utilities

Harmonic Mean

Computes the harmonic mean of numerical datasets, useful for averaging rates, ratios, and percentages. Access via MCP in AI coding assistants or REST API at `/v1/stats/harmonic-mean`. Returns precise calculations where arithmetic mean would be misleading — like average speeds or financial ratios. Handles edge cases like zeros and negative values appropriately.

API Endpoint

GET /v1/stats/harmonic-mean

Code Examples

curl "https://tinyfn.io/v1/stats/harmonic-mean" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/stats/harmonic-mean', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/stats/harmonic-mean',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's statistics tools:

{
  "mcpServers": {
    "tinyfn-stats": {
      "url": "https://tinyfn.io/mcp/stats",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

What is harmonic mean and when should I use it instead of arithmetic mean?

Harmonic mean is the reciprocal of the arithmetic mean of reciprocals, ideal for averaging rates, speeds, or ratios. Use it when values represent rates (like mph, fps) or when you need the average that preserves proportional relationships.

How does the MCP tool handle zeros or negative numbers in the dataset?

The tool returns an error for datasets containing zeros (division by zero) or negative numbers (undefined for harmonic mean). Filter your data before calling or use arithmetic/geometric means for mixed-sign datasets.

Can I calculate harmonic mean for very large datasets via the REST API?

Yes, send arrays via POST request to handle large datasets that exceed URL length limits. The endpoint processes thousands of values efficiently while maintaining numerical precision.

What's the difference between harmonic, arithmetic, and geometric means for performance metrics?

Harmonic mean best represents average rates (requests/sec, throughput), arithmetic mean for simple averages, geometric mean for growth rates. Harmonic mean is always ≤ geometric mean ≤ arithmetic mean.

How do I integrate this with Claude Code for analyzing benchmark data?

Use MCP to call the harmonic mean function directly in your analysis. Perfect for calculating average response times, throughput rates, or any performance metrics where extreme values shouldn't dominate the result.

Try Harmonic Mean Now

Get your free API key and start using Harmonic Mean in seconds.

Get Free API Key