repl.txt (1733B)
1 2 {{alias}}( arr, shape ) 3 Broadcasts an ndarray to a specified shape. 4 5 The returned array is a view on the input array data buffer. The view is 6 typically **not** contiguous. As more than one element of a returned view 7 may refer to the same memory location, writing to the view may affect 8 multiple elements. If you need to write to the returned array, copy the 9 array before performing operations which may mutate elements. 10 11 The returned array is a "base" ndarray, and, thus, the returned array does 12 not perform bounds checking or afford any of the guarantees of the non-base 13 ndarray constructor. The primary intent of this function is to broadcast an 14 ndarray-like object within internal implementations and to do so with 15 minimal overhead. 16 17 The function throws an error if a provided ndarray is incompatible with a 18 provided shape. 19 20 The function always returns a new ndarray instance even if the input ndarray 21 shape and the desired shape are the same. 22 23 Parameters 24 ---------- 25 arr: ndarray 26 Input array. 27 28 shape: ArrayLikeObject 29 Desired shape. 30 31 Returns 32 ------- 33 out: ndarray 34 Broadcasted array. 35 36 Examples 37 -------- 38 > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) 39 <ndarray> 40 > var sh = x.shape 41 [ 2, 2 ] 42 > var y = {{alias}}( x, [ 3, 2, 2 ] ) 43 <ndarray> 44 > sh = y.shape 45 [ 3, 2, 2 ] 46 > var v = y.get( 0, 0, 0 ) 47 1 48 > v = y.get( 0, 0, 1 ) 49 2 50 > v = y.get( 0, 1, 0 ) 51 3 52 > v = y.get( 0, 1, 1 ) 53 4 54 > v = y.get( 1, 0, 0 ) 55 1 56 > v = y.get( 1, 1, 0 ) 57 3 58 > v = y.get( 2, 0, 0 ) 59 1 60 > v = y.get( 2, 1, 1 ) 61 4 62 63 See Also 64 -------- 65