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)
| 1916 | |
| 1917 | @array_function_dispatch(_place_dispatcher) |
| 1918 | def place(arr, mask, vals): |
| 1919 | """ |
| 1920 | Change elements of an array based on conditional and input values. |
| 1921 | |
| 1922 | Similar to ``np.copyto(arr, vals, where=mask)``, the difference is that |
| 1923 | `place` uses the first N elements of `vals`, where N is the number of |
| 1924 | True values in `mask`, while `copyto` uses the elements where `mask` |
| 1925 | is True. |
| 1926 | |
| 1927 | Note that `extract` does the exact opposite of `place`. |
| 1928 | |
| 1929 | Parameters |
| 1930 | ---------- |
| 1931 | arr : ndarray |
| 1932 | Array to put data into. |
| 1933 | mask : array_like |
| 1934 | Boolean mask array. Must have the same size as `a`. |
| 1935 | vals : 1-D sequence |
| 1936 | Values to put into `a`. Only the first N elements are used, where |
| 1937 | N is the number of True values in `mask`. If `vals` is smaller |
| 1938 | than N, it will be repeated, and if elements of `a` are to be masked, |
| 1939 | this sequence must be non-empty. |
| 1940 | |
| 1941 | See Also |
| 1942 | -------- |
| 1943 | copyto, put, take, extract |
| 1944 | |
| 1945 | Examples |
| 1946 | -------- |
| 1947 | >>> arr = np.arange(6).reshape(2, 3) |
| 1948 | >>> np.place(arr, arr>2, [44, 55]) |
| 1949 | >>> arr |
| 1950 | array([[ 0, 1, 2], |
| 1951 | [44, 55, 44]]) |
| 1952 | |
| 1953 | """ |
| 1954 | return _place(arr, mask, vals) |
| 1955 | |
| 1956 | |
| 1957 | def disp(mesg, device=None, linefeed=True): |
no outgoing calls