fridom.framework.utils.array_ops.modify_array

Contents

fridom.framework.utils.array_ops.modify_array#

fridom.framework.utils.array_ops.modify_array(arr: ndarray, where: slice, value: ndarray) ndarray[source]#

Return a new array with the modifications.

Description#

A fundamental difference between JAX and NumPy is that NumPy allows in-place modification of arrays, while JAX does not. This function does not modify the input array in place, but returns a new array with the modifications.

Parameters#

arrnp.ndarray

The array to modify.

whereslice

The slice to modify.

valuenp.ndarray | float | int

The value to set.

Returns#

np.ndarray

The modified array.

Examples#

>>> import fridom.framework as fr
>>> x = fr.config.ncp.arange(10)  # create some array
>>> # instead of x[2:5] = 0, we use the modify_array function
>>> x = fr.utils.modify_array(x, slice(2,5), 0)