> ## 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.

# Stemfard matrix dimensions endpoints: nrows, ncols, shape

> Reference for the 4 Stemfard matrix dimensions endpoints — query a matrix's row count, column count, or full shape using the combined or individual endpoints.

The matrix dimensions endpoints let you programmatically inspect the size of a matrix. There are four endpoints in this group: a combined endpoint that accepts a `type` parameter to select the specific query, and three individual endpoints — `nrows`, `ncols`, and `shape`. All endpoints accept a single input matrix `a` and the full set of [common request parameters](/api-reference/overview#common-request-parameters).

Consider the following sample matrix used throughout the examples on this page:

```
A = [[3, 1, 4, 1],
     [5, 9, 2, 6],
     [5, 3, 5, 8]]
```

This is a **3 × 4** matrix: 3 rows and 4 columns.

***

## Combined endpoint

Use this endpoint to query any dimension property by setting the `type` field.

**`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions`**

### Parameters

<ParamField body="a" type="number[][]" required>
  The input matrix, expressed as an array of row arrays.
</ParamField>

<ParamField body="type" type="string" required>
  The dimension property to compute. Accepted values:

  * `"all"` — compute and return all dimension properties
  * `"nrows"` — number of rows
  * `"ncols"` — number of columns
  * `"shape"` — both dimensions as a `(rows, cols)` tuple
</ParamField>

<ParamField body="result_name" type="string" default="ans">
  Name assigned to the computed result in the response.
</ParamField>

<ParamField body="api_level" type="string" default="detailed">
  Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
</ParamField>

<ParamField body="steps_bg" type="boolean" default="true">
  Include background theory alongside solution steps.
</ParamField>

<ParamField body="steps_output_formats" type="string[]" default="[&#x22;&#x22;]">
  Format for step content: `"html"`, `"latex"`, or `"speech"`.
</ParamField>

<ParamField body="decimals" type="integer | null" default="null">
  Decimal precision for rounding. Pass `null` for full precision.
</ParamField>

<ParamField body="apply_decimals_in_steps" type="boolean" default="false">
  Apply `decimals` rounding to intermediate step values.
</ParamField>

<ParamField body="request_params" type="boolean" default="true">
  Include normalized request parameters in the response.
</ParamField>

<ParamField body="learning_pathways" type="boolean" default="true">
  Include curated learning resource links in the response.
</ParamField>

<ParamField body="related" type="boolean" default="true">
  Include links to related Stemfard endpoints in the response.
</ParamField>

<ParamField body="properties" type="boolean" default="true">
  Include a description of the result object's properties.
</ParamField>

### Example — query all dimension properties

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

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

  ```python Python theme={null}
  import requests

  data = requests.post(
      'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions',
      headers={
          'Authorization': 'Bearer <your-api-key>',
          'Content-Type': 'application/json',
      },
      json={
          'a': [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8]],
          'type': 'all',
          'result_name': 'dims',
          'api_level': 'standard',
      },
  ).json()
  ```
</CodeGroup>

```json 200 theme={null}
{
  "dims": {
    "nrows": 3,
    "ncols": 4,
    "shape": [3, 4]
  }
}
```

***

## Individual dimension endpoints

Each dimension query has its own focused endpoint. These do not accept a `type` field — the query is determined by the path.

<AccordionGroup>
  <Accordion title="POST .../matrix-dimensions/nrows — number of rows">
    Returns the number of rows in the input matrix.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/nrows`**

    <ParamField body="a" type="number[][]" required>
      The input matrix.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for rounding.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL 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": [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8]],
          "result_name": "row_count",
          "api_level": "lite"
        }'
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/nrows',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8]],
              'result_name': 'row_count',
              'api_level': 'lite',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "row_count": 3
    }
    ```
  </Accordion>

  <Accordion title="POST .../matrix-dimensions/ncols — number of columns">
    Returns the number of columns in the input matrix.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/ncols`**

    <ParamField body="a" type="number[][]" required>
      The input matrix.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for rounding.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL 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": [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8]],
          "result_name": "col_count",
          "api_level": "lite"
        }'
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/ncols',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8]],
              'result_name': 'col_count',
              'api_level': 'lite',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "col_count": 4
    }
    ```
  </Accordion>

  <Accordion title="POST .../matrix-dimensions/shape — rows and columns">
    Returns both dimensions as a `(rows, cols)` tuple. This is equivalent to querying `nrows` and `ncols` in a single request.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/shape`**

    <ParamField body="a" type="number[][]" required>
      The input matrix.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for rounding.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL 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": [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8]],
          "result_name": "matrix_shape",
          "api_level": "standard"
        }'
      ```

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

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-dimensions/shape',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8]],
              'result_name': 'matrix_shape',
              'api_level': 'standard',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "matrix_shape": [3, 4]
    }
    ```

    The response value is an array where the first element is the number of rows and the second element is the number of columns.
  </Accordion>
</AccordionGroup>
