Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Apply a callback to elements in an input ndarray and assign results to elements in an output ndarray.

License

NotificationsYou must be signed in to change notification settings

stdlib-js/ndarray-base-map

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!

map

NPM versionBuild StatusCoverage Status

Apply a callback function to elements in an input ndarray and assign results to elements in an output ndarray.

Usage

importmapfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-map@deno/mod.js';

map( arrays, fcn[, thisArg] )

Applies a callback function to elements in an input ndarray and assigns results to elements in an output ndarray.

importFloat64Arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@deno/mod.js';functionscale(x){returnx*10.0;}// Create data buffers:varxbuf=newFloat64Array([1.0,2.0,3.0,4.0,5.0,6.0]);varybuf=newFloat64Array(6);// Define the shape of the input and output arrays:varshape=[3,2];// Define the array strides:varsx=[2,1];varsy=[2,1];// Define the index offsets:varox=0;varoy=0;// Create the input and output ndarray-like objects:varx={'dtype':'float64','data':xbuf,'shape':shape,'strides':sx,'offset':ox,'order':'row-major'};vary={'dtype':'float64','data':ybuf,'shape':shape,'strides':sy,'offset':oy,'order':'row-major'};// Apply function:map([x,y],scale);console.log(y.data);// => <Float64Array>[ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 ]

The function accepts the following arguments:

  • arrays: array-like object containing one input ndarray and one output ndarray.
  • fcn: callback to apply.
  • thisArg: callback execution context.

The callback function is provided the following arguments:

  • value: current array element.
  • indices: current array element indices.
  • arr: the input ndarray.

Notes

  • Each provided ndarray should be an object with the following properties:

    • dtype: data type.
    • data: data buffer.
    • shape: dimensions.
    • strides: stride lengths.
    • offset: index offset.
    • order: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
  • For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a callback function in order to achieve better performance.

Examples

importdiscreteUniformfrom'https://cdn.jsdelivr.net/gh/stdlib-js/random-array-discrete-uniform@deno/mod.js';importzerosfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-zeros@deno/mod.js';importabsfrom'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@deno/mod.js';importshape2stridesfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@deno/mod.js';importndarray2arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-array@deno/mod.js';importnaryFunctionfrom'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@deno/mod.js';importmapfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-map@deno/mod.js';varN=10;varx={'dtype':'generic','data':discreteUniform(N,-100,100,{'dtype':'generic'}),'shape':[5,2],'strides':[2,1],'offset':0,'order':'row-major'};vary={'dtype':'generic','data':zeros(N,'generic'),'shape':x.shape.slice(),'strides':shape2strides(x.shape,'column-major'),'offset':0,'order':'column-major'};map([x,y],naryFunction(abs,1));console.log(ndarray2array(x.data,x.shape,x.strides,x.offset,x.order));console.log(ndarray2array(y.data,y.shape,y.strides,y.offset,y.order));

Notice

This package is part ofstdlib, a standard library 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 developstdlib, see the main projectrepository.

Community

Chat


License

SeeLICENSE.

Copyright

Copyright © 2016-2025. The StdlibAuthors.

About

Apply a callback to elements in an input ndarray and assign results to elements in an output ndarray.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp