MCPcopy Index your code
hub / github.com/numpy/numpy / place

Function place

numpy/lib/_function_base_impl.py:2112–2149  ·  view source on GitHub ↗

Change elements of an array based on conditional and input values. Similar to ``np.copyto(arr, vals, where=mask)``, the difference is that `place` uses the first N elements of `vals`, where N is the number of True values in `mask`, while `copyto` uses the elements where `mask`

(arr, mask, vals)

Source from the content-addressed store, hash-verified

2110
2111@array_function_dispatch(_place_dispatcher)
2112def place(arr, mask, vals):
2113 """
2114 Change elements of an array based on conditional and input values.
2115
2116 Similar to ``np.copyto(arr, vals, where=mask)``, the difference is that
2117 `place` uses the first N elements of `vals`, where N is the number of
2118 True values in `mask`, while `copyto` uses the elements where `mask`
2119 is True.
2120
2121 Note that `extract` does the exact opposite of `place`.
2122
2123 Parameters
2124 ----------
2125 arr : ndarray
2126 Array to put data into.
2127 mask : array_like
2128 Boolean mask array. Must have the same size as `arr`.
2129 vals : 1-D sequence
2130 Values to put into `arr`. Only the first N elements are used, where
2131 N is the number of True values in `mask`. If `vals` is smaller
2132 than N, it will be repeated, and if elements of `arr` are to be masked,
2133 this sequence must be non-empty.
2134
2135 See Also
2136 --------
2137 copyto, put, take, extract
2138
2139 Examples
2140 --------
2141 >>> import numpy as np
2142 >>> arr = np.arange(6).reshape(2, 3)
2143 >>> np.place(arr, arr>2, [44, 55])
2144 >>> arr
2145 array([[ 0, 1, 2],
2146 [44, 55, 44]])
2147
2148 """
2149 return _place(arr, mask, vals)
2150
2151
2152# See https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html

Callers 2

test_placeMethod · 0.90
test_bothMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_placeMethod · 0.72
test_bothMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…