repl.txt (9888B)
1 2 {{alias}}( dtype, buffer, shape, strides, offset, order ) 3 Returns an ndarray. 4 5 Parameters 6 ---------- 7 dtype: string 8 Underlying data type. 9 10 buffer: ArrayLikeObject|TypedArray|Buffer 11 Data buffer. A data buffer must be an array-like object (i.e., have a 12 `length` property). For data buffers which are not indexed collections 13 (i.e., collections which cannot support direct index access, such as 14 `buffer[ index ]`; e.g., Complex64Array, Complex128Array, etc), a data 15 buffer should provide `#.get( idx )` and `#.set( v[, idx] )` methods. 16 Note that, for `set` methods, the value to set should be the first 17 argument, followed by the linear index, similar to the native typed 18 array `set` method. 19 20 shape: ArrayLikeObject<integer> 21 Array shape. 22 23 strides: ArrayLikeObject<integer> 24 Array strides. 25 26 offset: integer 27 Index offset. 28 29 order: string 30 Specifies whether an array is row-major (C-style) or column-major 31 (Fortran-style). 32 33 Returns 34 ------- 35 ndarray: ndarray 36 ndarray instance. 37 38 Examples 39 -------- 40 // Create a new instance... 41 > var b = [ 1, 2, 3, 4 ]; // underlying data buffer 42 > var d = [ 2, 2 ]; // shape 43 > var s = [ 2, 1 ]; // strides 44 > var o = 0; // index offset 45 > var arr = {{alias}}( 'generic', b, d, s, o, 'row-major' ) 46 <ndarray> 47 48 // Get an element using subscripts: 49 > var v = arr.get( 1, 1 ) 50 4 51 52 // Get an element using a linear index: 53 > v = arr.iget( 3 ) 54 4 55 56 // Set an element using subscripts: 57 > arr.set( 1, 1, 40 ); 58 > arr.get( 1, 1 ) 59 40 60 61 // Set an element using a linear index: 62 > arr.iset( 3, 99 ); 63 > arr.get( 1, 1 ) 64 99 65 66 67 {{alias}}.prototype.byteLength 68 Size (in bytes) of the array (if known). 69 70 Returns 71 ------- 72 size: integer|null 73 Size (in bytes) of the array. 74 75 Examples 76 -------- 77 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 78 > var d = [ 2, 2 ]; 79 > var s = [ 2, 1 ]; 80 > var o = 0; 81 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 82 > var sz = arr.byteLength 83 32 84 85 86 {{alias}}.prototype.BYTES_PER_ELEMENT 87 Size (in bytes) of each array element (if known). 88 89 Returns 90 ------- 91 size: integer|null 92 Size (in bytes) of each array element. 93 94 Examples 95 -------- 96 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 97 > var d = [ 2, 2 ]; 98 > var s = [ 2, 1 ]; 99 > var o = 0; 100 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 101 > var sz = arr.BYTES_PER_ELEMENT 102 8 103 104 105 {{alias}}.prototype.data 106 Pointer to the underlying data buffer. 107 108 Returns 109 ------- 110 buf: ArrayLikeObject|TypedArray|Buffer 111 Underlying data buffer. 112 113 Examples 114 -------- 115 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 116 > var d = [ 2, 2 ]; 117 > var s = [ 2, 1 ]; 118 > var o = 0; 119 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 120 > var buf = arr.data 121 <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ] 122 123 124 {{alias}}.prototype.dtype 125 Underlying data type. 126 127 Returns 128 ------- 129 dtype: string 130 Underlying data type. 131 132 Examples 133 -------- 134 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 135 > var d = [ 2, 2 ]; 136 > var s = [ 2, 1 ]; 137 > var o = 0; 138 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 139 > var dt = arr.dtype 140 'float64' 141 142 143 {{alias}}.prototype.flags 144 Information about the memory layout of the array. 145 146 Returns 147 ------- 148 flags: Object 149 Info object. 150 151 Examples 152 -------- 153 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 154 > var d = [ 2, 2 ]; 155 > var s = [ 2, 1 ]; 156 > var o = 0; 157 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 158 > var fl = arr.flags 159 {...} 160 161 162 {{alias}}.prototype.length 163 Length of the array (i.e., number of elements). 164 165 Returns 166 ------- 167 len: integer 168 Array length. 169 170 Examples 171 -------- 172 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 173 > var d = [ 2, 2 ]; 174 > var s = [ 2, 1 ]; 175 > var o = 0; 176 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 177 > var len = arr.length 178 4 179 180 181 {{alias}}.prototype.ndims 182 Number of dimensions. 183 184 Returns 185 ------- 186 ndims: integer 187 Number of dimensions. 188 189 Examples 190 -------- 191 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 192 > var d = [ 2, 2 ]; 193 > var s = [ 2, 1 ]; 194 > var o = 0; 195 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 196 > var n = arr.ndims 197 2 198 199 200 {{alias}}.prototype.offset 201 Index offset which specifies the buffer index at which to start iterating 202 over array elements. 203 204 Returns 205 ------- 206 offset: integer 207 Index offset. 208 209 Examples 210 -------- 211 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 212 > var d = [ 2, 2 ]; 213 > var s = [ 2, 1 ]; 214 > var o = 0; 215 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 216 > var v = arr.offset 217 0 218 219 220 {{alias}}.prototype.order: string 221 Array order. 222 223 The array order is either row-major (C-style) or column-major (Fortran- 224 style). 225 226 Returns 227 ------- 228 order: string 229 Array order. 230 231 Examples 232 -------- 233 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 234 > var d = [ 2, 2 ]; 235 > var s = [ 2, 1 ]; 236 > var o = 0; 237 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 238 > var ord = arr.order 239 'row-major' 240 241 242 {{alias}}.prototype.shape 243 Array shape. 244 245 Returns 246 ------- 247 shape: Array 248 Array shape. 249 250 Examples 251 -------- 252 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 253 > var d = [ 2, 2 ]; 254 > var s = [ 2, 1 ]; 255 > var o = 0; 256 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 257 > var sh = arr.shape 258 [ 2, 2 ] 259 260 261 {{alias}}.prototype.strides 262 Index strides which specify how to access data along corresponding array 263 dimensions. 264 265 Returns 266 ------- 267 strides: Array 268 Index strides. 269 270 Examples 271 -------- 272 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 273 > var d = [ 2, 2 ]; 274 > var s = [ 2, 1 ]; 275 > var o = 0; 276 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 277 > var st = arr.strides 278 [ 2, 1 ] 279 280 281 {{alias}}.prototype.get( ...idx ) 282 Returns an array element specified according to provided subscripts. 283 284 The number of provided subscripts should equal the number of dimensions. 285 286 For zero-dimensional arrays, no indices should be provided. 287 288 Parameters 289 ---------- 290 idx: ...integer 291 Subscripts. 292 293 Returns 294 ------- 295 out: any 296 Array element. 297 298 Examples 299 -------- 300 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 301 > var d = [ 2, 2 ]; 302 > var s = [ 2, 1 ]; 303 > var o = 0; 304 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 305 > var v = arr.get( 1, 1 ) 306 4.0 307 308 309 {{alias}}.prototype.iget( idx ) 310 Returns an array element located at a specified linear index. 311 312 For zero-dimensional arrays, the input argument is ignored and, for clarity, 313 should not be provided. 314 315 Parameters 316 ---------- 317 idx: integer 318 Linear index. 319 320 Returns 321 ------- 322 out: any 323 Array element. 324 325 Examples 326 -------- 327 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 328 > var d = [ 2, 2 ]; 329 > var s = [ 2, 1 ]; 330 > var o = 0; 331 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 332 > var v = arr.iget( 3 ) 333 4.0 334 335 336 {{alias}}.prototype.set( ...idx, v ) 337 Sets an array element specified according to provided subscripts. 338 339 The number of provided subscripts should equal the number of dimensions. 340 341 For zero-dimensional arrays, no indices should be provided. 342 343 Parameters 344 ---------- 345 idx: ...integer 346 Subscripts. 347 348 v: any 349 Value to set. 350 351 Returns 352 ------- 353 out: ndarray 354 ndarray instance. 355 356 Examples 357 -------- 358 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 359 > var d = [ 2, 2 ]; 360 > var s = [ 2, 1 ]; 361 > var o = 0; 362 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 363 > arr.set( 1, 1, -4.0 ); 364 > arr.get( 1, 1 ) 365 -4.0 366 367 368 {{alias}}.prototype.iset( idx, v ) 369 Sets an array element located at a specified linear index. 370 371 For zero-dimensional arrays, the first, and only, argument should be the 372 value to set. 373 374 Parameters 375 ---------- 376 idx: integer 377 Linear index. 378 379 v: any 380 Value to set. 381 382 Returns 383 ------- 384 out: ndarray 385 ndarray instance. 386 387 Examples 388 -------- 389 > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 390 > var d = [ 2, 2 ]; 391 > var s = [ 2, 1 ]; 392 > var o = 0; 393 > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); 394 > arr.iset( 3, -4.0 ); 395 > arr.iget( 3 ) 396 -4.0 397 398 399 {{alias}}.prototype.toString() 400 Serializes an ndarray as a string. 401 402 This method does **not** serialize data outside of the buffer region defined 403 by the array configuration. 404 405 Returns 406 ------- 407 str: string 408 Serialized ndarray string. 409 410 Examples 411 -------- 412 > var b = [ 1, 2, 3, 4 ]; 413 > var d = [ 2, 2 ]; 414 > var s = [ 2, 1 ]; 415 > var o = 0; 416 > var arr = {{alias}}( 'generic', b, d, s, o, 'row-major' ); 417 > arr.toString() 418 '...' 419 420 421 {{alias}}.prototype.toJSON() 422 Serializes an ndarray as a JSON object. 423 424 This method does **not** serialize data outside of the buffer region defined 425 by the array configuration. 426 427 Returns 428 ------- 429 obj: Object 430 JSON object. 431 432 Examples 433 -------- 434 > var b = [ 1, 2, 3, 4 ]; 435 > var d = [ 2, 2 ]; 436 > var s = [ 2, 1 ]; 437 > var o = 0; 438 > var arr = {{alias}}( 'generic', b, d, s, o, 'row-major' ); 439 > arr.toJSON() 440 {...} 441 442 See Also 443 -------- 444