Return a new ndarray with the element at a specified index replaced by a provided value.
var ndarrayWith = require( '@stdlib/ndarray/with' );Returns a new ndarray with the element at a specified index replaced by a provided value.
var zeros = require( '@stdlib/ndarray/zeros' );
var x = zeros( [ 2, 2 ], {
'dtype': 'float64'
});
// returns <ndarray>
var out = ndarrayWith( x, [ 0, 0 ], 1.0 );
// returns <ndarray>
var v = out.get( 0, 0 );
// returns 1.0The function accepts the following arguments:
- x: input ndarray.
- indices: indices of the element to replace.
- value: replacement value.
- This function does not validate that a provided
valueis compatible with the data type of the input ndarray. For example, the function does not guard against precision loss whenvalueis a real-valued number and the input ndarray has an integer data type. This function should be considered a copy-on-write analog to using an ndarray'ssetmethod. Whether avalueis silently coerced to the data type of the input ndarray or triggers an exception when incompatible is implementation-dependent. Accordingly, any assertion logic ensuring data type compatibility should be performed before calling this function.
var zeros = require( '@stdlib/ndarray/zeros' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var ndarrayWith = require( '@stdlib/ndarray/with' );
var x = zeros( [ 1, 3, 3 ], {
'dtype': 'float64'
});
var out = ndarrayWith( x, [ 0, 1, 1 ], 10.0 );
console.log( ndarray2array( out ) );