MCPcopy Create free account
hub / github.com/dask/dask / setitem

Function setitem

dask/array/slicing.py:2030–2117  ·  view source on GitHub ↗

Chunk function of `setitem_array`. Assign v to indices of x. Parameters ---------- x : numpy/cupy/etc. array The array to be assigned to. v : numpy/cupy/etc. array The values which will be assigned. indices : list of `slice`, `int`, or numpy array Th

(x, v, indices)

Source from the content-addressed store, hash-verified

2028
2029
2030def setitem(x, v, indices):
2031 """Chunk function of `setitem_array`.
2032
2033 Assign v to indices of x.
2034
2035 Parameters
2036 ----------
2037 x : numpy/cupy/etc. array
2038 The array to be assigned to.
2039 v : numpy/cupy/etc. array
2040 The values which will be assigned.
2041 indices : list of `slice`, `int`, or numpy array
2042 The indices describing the elements of x to be assigned from
2043 v. One index per axis.
2044
2045 Note that an individual index can not be a `list`, use a 1-d
2046 numpy array instead.
2047
2048 If a 1-d numpy array index contains the non-valid value of the
2049 size of the corresponding dimension of x, then those index
2050 elements will be removed prior to the assignment (see
2051 `block_index_from_1d_index` function).
2052
2053 Returns
2054 -------
2055 numpy/cupy/etc. array
2056 A new independent array with assigned elements, unless v is
2057 empty (i.e. has zero size) in which case then the input array
2058 is returned and the indices are ignored.
2059
2060 Examples
2061 --------
2062 >>> x = np.arange(8).reshape(2, 4)
2063 >>> setitem(x, np.array(-99), [np.array([False, True])])
2064 array([[ 0, 1, 2, 3],
2065 [-99, -99, -99, -99]])
2066 >>> x
2067 array([[0, 1, 2, 3],
2068 [4, 5, 6, 7]])
2069 >>> setitem(x, np.array([-88, -99]), [slice(None), np.array([1, 3])])
2070 array([[ 0, -88, 2, -99],
2071 [ 4, -88, 6, -99]])
2072 >>> setitem(x, -x, [slice(None)])
2073 array([[ 0, -1, -2, -3],
2074 [-4, -5, -6, -7]])
2075 >>> x
2076 array([[0, 1, 2, 3],
2077 [4, 5, 6, 7]])
2078 >>> setitem(x, np.array([-88, -99]), [slice(None), np.array([4, 4, 3, 4, 1, 4])])
2079 array([[ 0, -99, 2, -88],
2080 [ 4, -99, 6, -88]])
2081 >>> value = np.where(x < 0)[0]
2082 >>> value.size
2083 0
2084 >>> y = setitem(x, value, [Ellipsis])
2085 >>> y is x
2086 True
2087 """

Callers 1

test_delayed_errorsFunction · 0.85

Calls 4

viewMethod · 0.80
prodMethod · 0.45
whereMethod · 0.45
copyMethod · 0.45

Tested by 1

test_delayed_errorsFunction · 0.68