Home
Getting Started
  • Fundamentals
  • Advanced
  • Fundamentals
  • Intermediate
  • Advanced
OM-Functions
  • FAQs
  • Glossary
  • Contributing
Changelog
Github
Home
Getting Started
  • Fundamentals
  • Advanced
  • Fundamentals
  • Intermediate
  • Advanced
OM-Functions
  • FAQs
  • Glossary
  • Contributing
Changelog
Github
  • OM-Functions

    • OM-Functions Overview
    • Arithmetic Operations
    • Array Operations
    • Logical Operations
    • Statistics
    • Transformations
    • Utilities

Statistics

These functions help calculate statistical measures from arrays:

1. mad.sum(array)

Returns the sum of all elements:

ParameterTypeDescription
arrayArrayInput array
ReturnsnumberTotal sum of elements

Example:

import { sum } from 'openmadness';

sum([1, 2, 3]);
// Result: 6

2. mad.mean(array)

Calculates the mean (average) of elements:

ParameterTypeDescription
arrayArrayInput array
ReturnsnumberAverage of elements

Example:

import { mean } from 'openmadness';

mean([1, 2, 3]);
// Result: 2

3. mad.std(array)

Computes the standard deviation of the array:

ParameterTypeDescription
arrayArrayInput array
ReturnsnumberStandard deviation

Example:

import { std } from 'openmadness';

std([1, 2, 3]);
// Result: ~0.82 (sample-dependent)

4. mad.median(array)

Finds the median value:

ParameterTypeDescription
arrayArrayInput array
ReturnsnumberMiddle value

Example:

import { median } from 'openmadness';

median([1, 3, 2]);
// Result: 2

Transformations

These functions are used to reshape or reformat arrays:

1. mad.reshape(array, newShape)

Reshapes an array to the specified shape:

ParameterTypeDescription
arrayArrayThe original array
newShapeArrayNew shape, e.g., [2, 2]
ReturnsArrayReshaped array

Example:

import { reshape } from 'openmadness';

reshape([1, 2, 3, 4], [2, 2]);
// Result: [[1, 2], [3, 4]]

2. mad.flatten(array)

Flattens a nested array into a 1D array:

ParameterTypeDescription
arrayArrayA nested array
ReturnsArrayFlattened 1D array
ReturnsArrayReshaped array

Example:

import { flatten } from 'openmadness';

flatten([[1, 2], [3, 4]]);
// Result: [1, 2, 3, 4]

3. mad.transpose(array)

Transposes a 2D array (rows become columns):

ParameterTypeDescription
array2D ArrayThe matrix to flip
ReturnsArrayTransposed matrix
ReturnsArrayReshaped array

Example:

import { transpose } from 'openmadness';

transpose([[1, 2], [3, 4]]);
// Result: [[1, 3], [2, 4]]
Edit this page on GitHub
Last Updated:: 7/11/25, 12:24 PM
Contributors: Dev-Liz
Prev
Logical Operations
Next
Transformations