# matrix-transpose

> Transposes a matrix by switching the row and column indices of a multidimensional array.

Latest version **1.0.3** (published 2024-08-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install matrix-transpose
pnpm add matrix-transpose
yarn add matrix-transpose
bun add matrix-transpose
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-08-30 |
| First published | 2020-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Mark |
| Maintainers | remarkablemark |
| Keywords | matrix-transpose, matrix, transpose, array, row, column |

## Links

- npm: https://www.npmjs.com/package/matrix-transpose
- Repository: https://github.com/remarkablemark/matrix-transpose
- Homepage: https://github.com/remarkablemark/matrix-transpose#readme
- Issues: https://github.com/remarkablemark/matrix-transpose/issues
- npm.io page: https://npm.io/package/matrix-transpose

## Alternatives

- [@snazzah/davey](https://npm.io/package/@snazzah/davey.md) — 1.5M weekly downloads
- [@vendure/testing](https://npm.io/package/@vendure/testing.md) — 8.3K weekly downloads
- [vue-simple-context-menu](https://npm.io/package/vue-simple-context-menu.md) — 6.6K weekly downloads
- [cypress-webpack-preprocessor-v5](https://npm.io/package/cypress-webpack-preprocessor-v5.md) — 2.1K weekly downloads
- [@backstage/plugin-catalog-backend-module-puppetdb](https://npm.io/package/@backstage/plugin-catalog-backend-module-puppetdb.md) — 1.3K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2024-08-30
- 1.0.2 — 2020-12-29
- 1.0.1 — 2020-12-28
- 1.0.0 — 2020-12-28
- 0.0.0 — 2020-12-27

## README

# matrix-transpose

[![NPM](https://nodei.co/npm/matrix-transpose.png)](https://nodei.co/npm/matrix-transpose/)

[![NPM version](https://img.shields.io/npm/v/matrix-transpose.svg)](https://www.npmjs.com/package/matrix-transpose)
[![Build Status](https://github.com/remarkablemark/matrix-transpose/workflows/build/badge.svg?branch=master)](https://github.com/remarkablemark/matrix-transpose/actions?query=workflow%3Abuild)
[![Coverage Status](https://coveralls.io/repos/github/remarkablemark/matrix-transpose/badge.svg?branch=master)](https://coveralls.io/github/remarkablemark/matrix-transpose?branch=master)

[Transposes](https://wikipedia.org/wiki/Transpose) a matrix by switching the row and column indices of a multidimensional array:

```
transpose(array)
```

In other words, it flips a matrix over its diagonal. Inspired by the [Replit](https://replit.com/@remarkablemark/Swap-array-row-and-column).

#### Example

```js
const { transpose } = require('matrix-transpose');

transpose([
  [1, 2],
  [3, 4],
  [5, 6],
]);
```

Output:

```json
[
  [1, 3, 5],
  [2, 4, 6]
]
```

[Replit](https://replit.com/@remarkablemark/matrix-transpose) | [JSFiddle](https://jsfiddle.net/remarkablemark/c5upm1bz/)

## Install

[NPM](https://www.npmjs.com/package/matrix-transpose):

```sh
npm install matrix-transpose --save
```

[Yarn](https://yarnpkg.com/package/matrix-transpose):

```sh
yarn add matrix-transpose
```

[CDN](https://unpkg.com/matrix-transpose/):

```html
<script src="https://unpkg.com/matrix-transpose@latest/umd/matrix-transpose.min.js"></script>
<script>
  window.MatrixTranspose.transpose(/* array */);
</script>
```

## Usage

Import module:

```js
// ES Modules
import { transpose } from 'matrix-transpose';

// CommonJS
const { transpose } = require('matrix-transpose');
```

Transpose matrix:

```js
transpose([
  [1, 2],
  [3, 4],
  [5, 6],
]);
```

Output:

```json
[
  [1, 3, 5],
  [2, 4, 6]
]
```

Transpose matrix with inconsistent column lengths:

```js
transpose([[1], [2, 3], [4, 5, 6]]);
```

Output:

```json
[
  [1, 2, 4],
  [, 3, 5],
  [, , 6]
]
```

### Options

#### excludeEmpty

When option `excludeEmpty` is set to `true`, then empty items are excluded:

```js
transpose([[1], [2, 3], [4, 5, 6]], { excludeEmpty: true });
```

Output:

```json
[[1, 2, 4], [3, 5], [6]]
```

## Testing

Run tests with coverage:

```sh
npm test
```

Run tests in watch mode:

```sh
npm run test:watch
```

Lint files:

```sh
npm run lint
```

Fix lint errors:

```sh
npm run lint:fix
```

## Release

Release and publish are automated by [Release Please](https://github.com/googleapis/release-please).

## License

[MIT](https://github.com/remarkablemark/matrix-transpose/blob/master/LICENSE)

---
_Source: https://npm.io/package/matrix-transpose · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
