> ## Documentation Index
> Fetch the complete documentation index at: https://docsa.stemfard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# A guide to the Stemfard matrix operation endpoints

> Learn how to perform matrix arithmetic, element-wise operations, dimension queries, and statistical analysis using the Stemfard linear algebra endpoints.

The Stemfard API gives you a complete set of matrix operation endpoints under the `/api/v1/mathematics/linear-algebra/matrix-operations` path. This guide walks through every available category — arithmetic, element-wise operations, dimension queries, and statistics — and shows you concrete request and response examples so you can integrate them into your application quickly.

<Note>
  All endpoints accept an `api_level` parameter (`"lite"`, `"standard"`, or `"detailed"`) that controls how much solution detail the API returns alongside your result. See [API levels](/concepts/api-levels) for a full breakdown.
</Note>

## Matrix arithmetic

Use the arithmetic endpoints to add, subtract, or multiply matrices. You can call the unified endpoint with an `operation` field, or use a dedicated sub-path for clarity.

**Supported `operation` values:** `"add"`, `"subtract"`, `"multiply-ew"`, `"divide-ew"`, `"raise-ew"`, `"matmul"`, `"all"`

### Addition

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[1, 2], [3, 4]],
      "b": [[5, 6], [7, 8]],
      "api_level": "lite",
      "result_name": "sum"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer <your-api-key>',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        a: [[1, 2], [3, 4]],
        b: [[5, 6], [7, 8]],
        api_level: 'lite',
        result_name: 'sum',
      }),
    }
  );
  const data = await response.json();
  ```
</CodeGroup>

**Sample response**

```json theme={null}
{
  "result_name": "sum",
  "result": [[6, 8], [10, 12]],
  "steps": null
}
```

### Subtraction

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/subtract \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[9, 8], [7, 6]],
      "b": [[1, 2], [3, 4]],
      "api_level": "lite",
      "result_name": "diff"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/subtract',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer <your-api-key>',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        a: [[9, 8], [7, 6]],
        b: [[1, 2], [3, 4]],
        api_level: 'lite',
        result_name: 'diff',
      }),
    }
  );
  const data = await response.json();
  ```
</CodeGroup>

**Sample response**

```json theme={null}
{
  "result_name": "diff",
  "result": [[8, 6], [4, 2]],
  "steps": null
}
```

### Matrix multiplication (matmul)

Matrix multiplication (dot product) requires the column count of `a` to equal the row count of `b`.

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/matmul \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[1, 2], [3, 4]],
      "b": [[5, 6], [7, 8]],
      "api_level": "lite",
      "result_name": "product"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/matmul',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer <your-api-key>',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        a: [[1, 2], [3, 4]],
        b: [[5, 6], [7, 8]],
        api_level: 'lite',
        result_name: 'product',
      }),
    }
  );
  const data = await response.json();
  ```
</CodeGroup>

**Sample response**

```json theme={null}
{
  "result_name": "product",
  "result": [[19, 22], [43, 50]],
  "steps": null
}
```

## Element-wise operations

Element-wise operations apply a function independently to each corresponding pair of elements across two matrices of the same shape. The matrices must have identical dimensions; no broadcasting is applied.

| Endpoint suffix | Operation           | Description                                        |
| --------------- | ------------------- | -------------------------------------------------- |
| `/multiply-ew`  | `a[i][j] * b[i][j]` | Multiply each element by its counterpart           |
| `/divide-ew`    | `a[i][j] / b[i][j]` | Divide each element by its counterpart             |
| `/raise-ew`     | `a[i][j] ^ b[i][j]` | Raise each element to the power of its counterpart |

<CodeGroup>
  ```bash element-wise multiply theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/multiply-ew \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[1, 2], [3, 4]],
      "b": [[2, 3], [4, 5]],
      "api_level": "lite",
      "result_name": "ew_product"
    }'
  ```

  ```bash element-wise divide theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/divide-ew \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[10, 20], [30, 40]],
      "b": [[2, 4], [5, 8]],
      "api_level": "lite",
      "result_name": "ew_quotient"
    }'
  ```

  ```bash element-wise power theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/raise-ew \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[2, 3], [4, 5]],
      "b": [[3, 2], [2, 3]],
      "api_level": "lite",
      "result_name": "ew_power"
    }'
  ```
</CodeGroup>

**Sample response (multiply-ew)**

```json theme={null}
{
  "result_name": "ew_product",
  "result": [[2, 6], [12, 20]],
  "steps": null
}
```

## Matrix dimensions

The dimension endpoints let you inspect the shape of any matrix without performing a computation. This is useful for validating input before passing matrices to arithmetic or statistics endpoints.

<CodeGroup>
  ```bash shape theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/shape \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[1, 2, 3], [4, 5, 6]],
      "api_level": "lite"
    }'
  ```

  ```bash row count theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/nrows \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[1, 2, 3], [4, 5, 6]],
      "api_level": "lite"
    }'
  ```

  ```bash column count theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/ncols \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[1, 2, 3], [4, 5, 6]],
      "api_level": "lite"
    }'
  ```
</CodeGroup>

**Sample responses**

```json theme={null}
// shape
{ "result": [2, 3] }

// nrows
{ "result": 2 }

// ncols
{ "result": 3 }
```

## Matrix statistics

The statistics endpoints compute descriptive statistics across rows, columns, or the entire matrix. You can call the unified `/matrix-statistics` endpoint, or use a dedicated path for the specific statistic you need.

Available statistics: `row-min`, `col-min`, `mat-min`, `row-max`, `col-max`, `mat-max`, `row-sum`, `col-sum`, `mat-sum`, `row-mean`, `col-mean`, `mat-mean`, `row-median`, `col-median`, `mat-median`, `row-var`, `col-var`, `mat-var`, `row-std`, `col-std`, `mat-std`

### Row mean

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-statistics/row-mean \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[2, 4, 6], [1, 3, 5]],
      "api_level": "lite",
      "result_name": "row_means",
      "decimals": 4
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-statistics/row-mean',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer <your-api-key>',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        a: [[2, 4, 6], [1, 3, 5]],
        api_level: 'lite',
        result_name: 'row_means',
        decimals: 4,
      }),
    }
  );
  const data = await response.json();
  ```
</CodeGroup>

**Sample response**

```json theme={null}
{
  "result_name": "row_means",
  "result": [4.0, 3.0],
  "steps": null
}
```

### Matrix sum

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-statistics/mat-sum \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[1, 2], [3, 4], [5, 6]],
      "api_level": "lite",
      "result_name": "total"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-statistics/mat-sum',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer <your-api-key>',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        a: [[1, 2], [3, 4], [5, 6]],
        api_level: 'lite',
        result_name: 'total',
      }),
    }
  );
  const data = await response.json();
  ```
</CodeGroup>

**Sample response**

```json theme={null}
{
  "result_name": "total",
  "result": 21,
  "steps": null
}
```

### Column standard deviation

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-statistics/col-std \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[2, 4], [4, 8], [6, 12]],
      "api_level": "lite",
      "result_name": "col_stds",
      "decimals": 4
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-statistics/col-std',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer <your-api-key>',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        a: [[2, 4], [4, 8], [6, 12]],
        api_level: 'lite',
        result_name: 'col_stds',
        decimals: 4,
      }),
    }
  );
  const data = await response.json();
  ```
</CodeGroup>

**Sample response**

```json theme={null}
{
  "result_name": "col_stds",
  "result": [1.6330, 3.2660],
  "steps": null
}
```
