GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - stdlib-js/ndarray: Multidimensional arrays.

BranchesTags
Open more actions menu

Latest commit

 

History

1,559 Commits
1,559 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
any-by
any-by
 
 
any
any
 
 
array
array
 
 
at
at
 
 
base
base
 
 
broadcast-array
broadcast-array
 
 
broadcast-arrays
broadcast-arrays
 
 
broadcast-scalar-like
broadcast-scalar-like
 
 
broadcast-scalar
broadcast-scalar
 
 
casting-modes
casting-modes
 
 
colcat
colcat
 
 
concat
concat
 
 
concat1d
concat1d
 
 
copy
copy
 
 
count-falsy
count-falsy
 
 
count-if
count-if
 
 
count-truthy
count-truthy
 
 
ctor
ctor
 
 
data-buffer
data-buffer
 
 
defaults
defaults
 
 
diagonal
diagonal
 
 
dispatch-by
dispatch-by
 
 
dispatch
dispatch
 
 
docs/types
docs/types
 
 
dtype-ctor
dtype-ctor
 
 
dtype
dtype
 
 
dtypes
dtypes
 
 
empty-like
empty-like
 
 
empty
empty
 
 
every-by
every-by
 
 
every
every
 
 
examples
examples
 
 
falses-like
falses-like
 
 
falses
falses
 
 
fancy
fancy
 
 
fill-by
fill-by
 
 
fill-slice
fill-slice
 
 
fill
fill
 
 
filter-map
filter-map
 
 
filter
filter
 
 
find-last
find-last
 
 
find
find
 
 
first
first
 
 
flag
flag
 
 
flags
flags
 
 
flatten-by
flatten-by
 
 
flatten-from-by
flatten-from-by
 
 
flatten-from
flatten-from
 
 
flatten
flatten
 
 
fliplr
fliplr
 
 
flipud
flipud
 
 
for-each
for-each
 
 
from-arraybuffer
from-arraybuffer
 
 
from-scalar-like
from-scalar-like
 
 
from-scalar
from-scalar
 
 
hconcat
hconcat
 
 
includes
includes
 
 
ind2sub
ind2sub
 
 
index-modes
index-modes
 
 
index
index
 
 
input-casting-policies
input-casting-policies
 
 
iter
iter
 
 
last
last
 
 
lib
lib
 
 
map
map
 
 
matrix
matrix
 
 
maybe-broadcast-array
maybe-broadcast-array
 
 
maybe-broadcast-arrays
maybe-broadcast-arrays
 
 
min-dtype
min-dtype
 
 
mostly-safe-casts
mostly-safe-casts
 
 
nans-like
nans-like
 
 
nans
nans
 
 
ndarraylike2ndarray
ndarraylike2ndarray
 
 
ndarraylike2scalar
ndarraylike2scalar
 
 
ndims
ndims
 
 
next-dtype
next-dtype
 
 
numel-dimension
numel-dimension
 
 
numel
numel
 
 
offset
offset
 
 
ones-like
ones-like
 
 
ones
ones
 
 
order
order
 
 
orders
orders
 
 
output-dtype-policies
output-dtype-policies
 
 
pop
pop
 
 
prepend-singleton-dimensions
prepend-singleton-dimensions
 
 
promotion-rules
promotion-rules
 
 
push
push
 
 
reject
reject
 
 
remove-singleton-dimensions
remove-singleton-dimensions
 
 
reverse-dimension
reverse-dimension
 
 
reverse-dimensions
reverse-dimensions
 
 
reverse
reverse
 
 
rot180
rot180
 
 
rot90
rot90
 
 
rotl90
rotl90
 
 
rotr90
rotr90
 
 
rowcat
rowcat
 
 
safe-casts
safe-casts
 
 

Repository files navigation

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

ndarray

NPM version Build Status Coverage Status

Multidimensional arrays.

Installation

npm install @stdlib/ndarray

Alternatively,

  • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
  • If you are using Deno, visit the deno branch (see README for usage intructions).
  • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (see README).

The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.

To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.

Usage

var ns = require( '@stdlib/ndarray' );

ns

ndarray namespace.

var o = ns;
// returns {...}
Creation

The namespace exports the following functions to create multidimensional arrays:

  • array( [buffer,] [options] ): create a multidimensional array.
  • copy( x[, options] ): copy an input ndarray to a new ndarray having the same shape and data type.
  • ndarray( dtype, buffer, shape, strides, offset, order[, options] ): multidimensional array constructor.
  • emptyLike( x[, options] ): create an uninitialized ndarray having the same shape and data type as a provided ndarray.
  • empty( shape[, options] ): create an uninitialized ndarray having a specified shape and data type.
  • falsesLike( x[, options] ): create an ndarray filled with false values and having the same shape and data type as a provided ndarray.
  • falses( shape[, options] ): create an ndarray filled with false values and having a specified shape and data type.
  • FancyArray( dtype, buffer, shape, strides, offset, order[, options] ): fancy multidimensional array constructor.
  • scalar2ndarrayLike( x, value[, options] ): convert a scalar value to a zero-dimensional ndarray having the same data-type as a provided ndarray.
  • scalar2ndarray( value[, options] ): convert a scalar value to a zero-dimensional ndarray.
  • nansLike( x[, options] ): create a NaN-filled ndarray having the same shape and data type as a provided ndarray.
  • nans( shape[, options] ): create a NaN-filled ndarray having a specified shape and data type.
  • ndarraylike2ndarray( x[, options] ): convert an ndarray-like object to an ndarray.
  • onesLike( x[, options] ): create a ones-filled ndarray having the same shape and data type as a provided ndarray.
  • ones( shape[, options] ): create a ones-filled ndarray having a specified shape and data type.
  • ndarray2fancy( x[, options] ): convert an ndarray to an object supporting fancy indexing.
  • truesLike( x[, options] ): create an ndarray filled with true values and having the same shape and data type as a provided ndarray.
  • trues( shape[, options] ): create an ndarray filled with true values and having a specified shape and data type.
  • zerosLike( x[, options] ): create a zero-filled ndarray having the same shape and data type as a provided ndarray.
  • zeros( shape[, options] ): create a zero-filled ndarray having a specified shape and data type.
Manipulation

The namespace exports the following functions to manipulate multidimensional arrays:

  • broadcastArray( x, shape ): broadcast an ndarray to a specified shape.
  • broadcastArrays( ...arrays ): broadcast ndarrays to a common shape.
  • broadcastScalarLike( x, value[, options] ): broadcast a scalar value to an ndarray having the same shape and data-type as a provided input ndarray.
  • broadcastScalar( value, shape[, options] ): broadcast a scalar value to an ndarray of a specified shape.
  • colcat( arrays ): concatenate a list of one-dimensional or two-dimensional ndarrays as columns.
  • concat( arrays[, options] ): concatenate a list of ndarrays along a specified ndarray dimension.
  • concat1d( ...arrays ): return a one-dimensional ndarray formed by concatenating provided input arguments.
  • diagonal( x[, options] ): return a read-only view of the diagonal of a matrix (or stack of matrices).
  • fillBy( x, fcn[, thisArg] ): fill an input ndarray according to a callback function.
  • fillSlice( x, value, ...s[, options] ): fill an input ndarray view with a specified value.
  • fill( x, value ): fill an input ndarray with a specified value.
  • flattenBy( x[, options], fcn[, thisArg] ): flatten an ndarray according to a callback function.
  • flattenFromBy( x, dim[, options], fcn[, thisArg] ): flatten an ndarray according to a callback function starting from a specified dimension.
  • flattenFrom( x, dim[, options] ): return a copy of an input ndarray where all dimensions of the input ndarray are flattened starting from a specified dimension.
  • flatten( x[, options] ): return a flattened copy of an input ndarray.
  • fliplr( x ): return a read-only view of an input ndarray in which the order of elements along the last dimension is reversed.
  • flipud( x ): return a read-only view of an input ndarray in which the order of elements along the second-to-last dimension is reversed.
  • hconcat( arrays ): concatenate a list of ndarrays along the last dimension.
  • map( x[, options], fcn[, thisArg] ): apply a callback function to elements in an input ndarray and assign results to elements in a new output ndarray.
  • maybeBroadcastArray( x, shape ): broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.
  • maybeBroadcastArrays( arrays ): broadcast ndarrays to a common shape.
  • pop( x[, options] ): return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension.
  • prependSingletonDimensions( x, n ): return a read-only view of an input ndarray with a specified number of prepended singleton dimensions.
  • push( x, ...values ): return a one-dimensional ndarray formed by appending provided scalar values to a one-dimensional input ndarray.
  • removeSingletonDimensions( x ): return a read-only view of an input ndarray with singleton dimensions removed.
  • reverseDimension( x, dim ): return a read-only view of an input ndarray in which the order of elements along a specified dimension is reversed.
  • reverseDimensions( x, dims ): return a read-only view of an input ndarray in which the order of elements along specified dimensions is reversed.
  • reverse( x ): return a read-only view of an input ndarray in which the order of elements along each dimension is reversed.
  • rot180( x[, options] ): return a read-only view of an input ndarray rotated 180 degrees in a specified plane.
  • rot90( x[, options] ): return a read-only view of an input ndarray rotated 90 degrees in a specified plane.
  • rotl90( x, k ): return a read-only view of a matrix (or a stack of matrices) rotated 90 degrees counterclockwise.
  • rotr90( x, k ): return a read-only view of a matrix (or a stack of matrices) rotated 90 degrees clockwise.
  • rowcat( arrays ): concatenate a list of one-dimensional or two-dimensional ndarrays as rows.
  • shift( x[, options] ): return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension.
  • sliceAssign( x, y, ...s[, options] ): assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.
  • sliceDimensionFrom( x, dim, start[, options] ): return a read-only shifted view of an input ndarray along a specified dimension.
  • sliceDimensionTo( x, dim, stop[, options] ): return a read-only truncated view of an input ndarray along a specified dimension.
  • sliceDimension( x, dim, slice[, options] ): return a read-only view of an input ndarray when sliced along a specified dimension.
  • sliceFrom( x, ...start[, options] ): return a read-only shifted view of an input ndarray.
  • sliceTo( x, ...stop[, options] ): return a read-only truncated view of an input ndarray.
  • slice( x, ...s[, options] ): return a read-only view of an input ndarray.
  • spreadDimensions( ndims, x, dims ): return a read-only view of an input ndarray where the dimensions of the input ndarray are expanded to a specified dimensionality by spreading dimensions to specified dimension indices and inserting dimensions of size one for the remaining dimensions.
  • toFlippedlr( x ): return a new ndarray where the order of elements along the last dimension of an input ndarray is reversed.
  • toFlippedud( x ): return a new ndarray where the order of elements along the second-to-last dimension of an input ndarray is reversed.
  • toReversedDimension( x[, options] ): return a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed.
  • toReversedDimensions( x, dims ): return a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed.
  • toReversed( x ): return a new ndarray where the order of elements of an input ndarray is reversed along each dimension.
  • toRot180( x[, options] ): return a new ndarray where an input ndarray is rotated 180 degrees in a specified plane.
  • toRot90( x[, options] ): return a new ndarray where an input ndarray is rotated 90 degrees in a specified plane.
  • toRotl90( x, k ): return a new ndarray where a matrix (or a stack of matrices) is rotated 90 degrees counterclockwise.
  • toRotr90( x, k ): return a new ndarray where a matrix (or a stack of matrices) is rotated 90 degrees clockwise.
  • toTransposed( x ): return a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed.
  • toUnflattened( x, dim, sizes ): return a new ndarray in which a specified dimension of an input ndarray is expanded over multiple dimensions.
  • transpose( x ): return a read-only view of an input ndarray in which the last two dimensions are transposed.
  • unflatten( x, dim, sizes ): return a read-only view of an input ndarray in which a specified dimension is expanded over multiple dimensions.
  • unshift( x, ...values ): return a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray.
  • vconcat( arrays ): concatenate a list of ndarrays along the second-to-last dimension.
  • ndarrayWith( x, indices, value ): return a new ndarray with the element at a specified index replaced by a provided value.
Search

The namespace exports the following functions to search multidimensional arrays:

  • anyBy( x[, options], predicate[, thisArg] ): test whether at least one element along one or more ndarray dimensions passes a test implemented by a predicate function.
  • any( x[, options] ): test whether at least one element along one or more ndarray dimensions is truthy.
  • countFalsy( x[, options] ): count the number of falsy elements along one or more ndarray dimensions.
  • countIf( x[, options], predicate[, thisArg] ): count the number of truthy elements along one or more ndarray dimensions.
  • countTruthy( x[, options] ): count the number of truthy elements along one or more ndarray dimensions.
  • everyBy( x[, options], predicate[, thisArg] ): test whether all elements along one or more ndarray dimensions pass a test implemented by a predicate function.
  • every( x[, options] ): test whether every element along one or more ndarray dimensions is truthy.
  • filterMap( x[, options], fcn[, thisArg] ): filter and map elements in an input ndarray to elements in a new output ndarray according to a callback function.
  • filter( x[, options], predicate[, thisArg] ): return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.
  • findLast( x[, options], predicate[, thisArg] ): return a new ndarray containing the last elements which pass a test implemented by a predicate function along one or more ndarray dimensions.
  • find( x[, options], predicate[, thisArg] ): return a new ndarray containing the first elements which pass a test implemented by a predicate function along one or more ndarray dimensions.
  • includes( x, searchElement[, options] ): test whether an ndarray contains a specified value along one or more dimensions.
  • reject( x[, options], predicate[, thisArg] ): return a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function.
  • someBy( x, n[, options], predicate[, thisArg] ): test whether at least n elements along one or more ndarray dimensions pass a test implemented by a predicate function.
  • some( x, n[, options] ): test whether at least n elements along one or more ndarray dimensions are truthy.
Inspection

The namespace exports the following functions to inspect multidimensional arrays:

  • dataBuffer( x ): return the underlying data buffer of a provided ndarray.
  • dtype( x ): return the data type of a provided ndarray.
  • flag( x, name ): return a specified flag for a provided ndarray.
  • flags( x ): return the flags of a provided ndarray.
  • ndims( x ): return the number of ndarray dimensions.
  • numelDimension( x, dim ): return the size (i.e., number of elements) of a specified dimension for a provided ndarray.
  • numel( x ): return the number of elements in an ndarray.
  • offset( x ): return the index offset specifying the underlying buffer index of the first iterated ndarray element.
  • order( x ): return the layout order of a provided ndarray.
  • shape( x ): return the shape of a provided ndarray.
  • stride( x, dim ): return the stride along a specified dimension for a provided ndarray.
  • strides( x ): return the strides of a provided ndarray.
Indexing

The namespace exports the following functions to index multidimensional arrays:

  • at( x[, ...indices] ): return an ndarray element.
  • first( x[, options] ): return a read-only view of the first element (or subarray) along one or more ndarray dimensions.
  • ind2sub( shape, idx[, options] ): convert a linear index to an array of subscripts.
  • indexModes(): list of ndarray index modes.
  • ndindex( x[, options] ): ndarray index constructor.
  • last( x[, options] ): return a read-only view of the last element (or subarray) along one or more ndarray dimensions.
  • sub2ind( shape, ...subscripts[, options] ): convert subscripts to a linear index.
Conversion

The namespace exports the following functions to convert multidimensional arrays:

  • ndarraylike2scalar( x ): convert an ndarray-like object to a scalar value.
  • ndarray2array( x ): convert an ndarray to a generic array.
  • ndarray2json( x ): serialize an ndarray as a JSON object.
  • ndarray2localeString( x[, locales[, options]] ): serialize an ndarray as a locale-aware string.
  • ndarray2string( x ): serialize an ndarray as a string.
Data Types

The namespace exports the following functions for working with multidimensional array data types:

  • castingModes(): list of ndarray casting modes.
  • DataType( value[, options] ): data type constructor.
  • dtypes( [kind] ): list of ndarray data types.
  • inputCastingPolicies(): list of input ndarray casting policies.
  • minDataType( value ): determine the minimum ndarray data type of the closest "kind" necessary for storing a provided scalar value.
  • mostlySafeCasts( [dtype] ): return a list of ndarray data types to which a provided ndarray data type can be safely cast and, for floating-point data types, can be downcast.
  • nextDataType( [dtype] ): return the next larger ndarray data type of the same kind.
  • outputDataTypePolicies(): list of output ndarray data type policies.
  • promotionRules( [dtype1, dtype2] ): return the ndarray data type with the smallest size and closest "kind" to which ndarray data types can be safely cast.
  • safeCasts( [dtype] ): return a list of ndarray data types to which a provided ndarray data type can be safely cast.
  • sameKindCasts( [dtype] ): return a list of ndarray data types to which a provided ndarray data type can be safely cast or cast within the same "kind".
Sub-namespaces

The namespace contains the following sub-namespaces:

  • base: base ndarray.
  • iter: multidimensional array iterators.
  • vector: vector constructors and associated utilities.
Utilities

The namespace contains the following multidimensional array utility functions:

  • defaults(): default ndarray settings.
  • dispatch( fcns, types, data, nargs, nin, nout ): create an ndarray function interface which performs multiple dispatch.
  • forEach( x, fcn[, thisArg] ): invoke a callback function once for each ndarray element.
  • arraybuffer2ndarray( dtype, buffer, shape, strides, byteOffset, order[, options] ): create an ndarray from an ArrayBuffer.
  • matrix: matrix constructors and associated utilities.
  • orders(): list of ndarray orders.

Examples

var objectKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/ndarray' );

console.log( objectKeys( ns ) );

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2026. The Stdlib Authors.

About

Multidimensional arrays.

github.com/stdlib-js/stdlib

Topics

arraybufferdatajavascriptmatrixmultidimensionalnamespacendarraynodenode-jsnodejsnsstdlibstructurestensortypedtyped-arraytypesvector

Resources

Readme
Apache-2.0 license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

16 stars

Watchers

2 watching

Forks

2 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.