Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/eye/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# eye

> Create a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var eye = require( '@stdlib/ndarray/base/eye' );
```

#### eye( dtype, rows, cols, k, order )

Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere.

```javascript
var getShape = require( '@stdlib/ndarray/shape' );
var getDType = require( '@stdlib/ndarray/dtype' );

var arr = eye( 'float64', 3, 3, 0, 'row-major');
// returns <ndarray>[ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ]

var sh = getShape( arr );
// returns [ 3, 3 ]

var dt = String( getDType( arr ) );
// returns 'float64'
```

The function accepts the following arguments:

- **dtype**: underlying [data type][@stdlib/ndarray/dtypes].
- **rows**: number of rows.
- **cols**: number of columns.
- **k**: diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal.
- **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style).


</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- If the provided [data type][@stdlib/ndarray/dtypes] is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero.
- If `k` is greater than the number of columns or less than the number of negative rows, the function returns an ndarray filled with zeros.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var eye = require( '@stdlib/ndarray/base/eye' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );

var arr = eye( 'float64', 3, 3, 1, 'row-major');
console.log( ndarray2array( arr ) );

arr = eye( 'complex64', 3, 3, 1, 'row-major');
console.log( ndarray2array( arr ) );
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes

</section>

<!-- /.links -->
Loading