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

Create a typed array.

License

NotificationsYou must be signed in to change notification settings

stdlib-js/array-typed

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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!

typedarray

NPM versionBuild StatusCoverage Status

Create a typed array.

Usage

importtypedarrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-typed@deno/mod.js';

typedarray( [dtype] )

Creates atyped array having a specifieddata type.

vararr=typedarray();// returns <Float64Array>

By default, the outputtyped array data type isfloat64. To specify an alternative data type, provide adtype argument.

vararr=typedarray('int32');// returns <Int32Array>

typedarray( length[, dtype] )

Returns atyped array having a specifiedlength.

vararr1=typedarray(5);// returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ]vararr2=typedarray(5,'uint8');// returns <Uint8Array>[ 0, 0, 0, 0, 0 ]

typedarray( typedarray[, dtype] )

Creates atyped array from anothertyped array.

vararr1=typedarray([5.0,-3.0,2.0]);// returns <Float64Array>[ 5.0, -3.0, 2.0 ]vararr2=typedarray(arr1);// returns <Float64Array>[ 5.0, -3.0, 2.0 ]vararr3=typedarray(arr1,'int32');// returns <Int32Array>[ 5, -3, 2 ]

typedarray( obj[, dtype] )

Creates atyped array from an array-like object or iterable.

vararr1=typedarray([0.5,0.5,0.5]);// returns <Float64Array>[ 0.5, 0.5, 0.5 ]vararr2=typedarray([0.5,0.5,0.5],'float32');// returns <Float32Array>[ 0.5, 0.5, 0.5 ]

Ifdtype is complex number data type and an array-like object contains interleaved real and imaginary components, the array-like object must have a length which is a multiple of two.

typedarray( buffer[, byteOffset[, length]][, dtype] )

Returns atyped array view of anArrayBuffer.

importArrayBufferfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@deno/mod.js';varbuf=newArrayBuffer(32);vararr1=typedarray(buf);// returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0 ]vararr2=typedarray(buf,'float32');// returns <Float32Array>[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]vararr3=typedarray(buf,16);// returns <Float64Array>[ 0.0, 0.0 ]vararr4=typedarray(buf,16,'float32');// returns <Float32Array>[ 0.0, 0.0, 0.0, 0.0 ]vararr5=typedarray(buf,16,1);// returns <Float64Array>[ 0.0 ]vararr6=typedarray(buf,10,4,'int16');// returns <Int16Array>[ 0, 0, 0, 0 ]

Notes

  • When providing a complex number array, ifdtype is unspecified or the specified data type is not a complex number data type, the returned array contains interleaved real and imaginary components.

Examples

importrandufrom'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@deno/mod.js';importtypedarrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-typed@deno/mod.js';vararr=typedarray(100,'float64');vari;for(i=0;i<arr.length;i++){arr[i]=randu()*100.0;}console.log(arr);

See Also


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.

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp