Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
Apply a callback to elements in an input ndarray and assign results to elements in an output ndarray.
License
stdlib-js/ndarray-base-map
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
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!
Apply a callback function to elements in an input ndarray and assign results to elements in an output ndarray.
To use in Observable,
map=require('https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-map@umd/browser.js')
To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:
varmap=require('path/to/vendor/umd/ndarray-base-map/index.js')
To include the bundle in a webpage,
<scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-map@umd/browser.js"></script>
If no recognized module system is present, access bundle contents via the global scope:
<scripttype="text/javascript">(function(){window.map;})();</script>
Applies a callback function to elements in an input ndarray and assigns results to elements in an output ndarray.
varFloat64Array=require('@stdlib/array-float64');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.
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.
<!DOCTYPE html><htmllang="en"><body><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/random-array-discrete-uniform@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-zeros@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-to-array@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-function@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-map@umd/browser.js"></script><scripttype="text/javascript">(function(){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));})();</script></body></html>
This package is part ofstdlib, 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 developstdlib, see the main projectrepository.
SeeLICENSE.
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.