MCPcopy Create free account
hub / github.com/numpy/numpy / place

Function place

numpy/lib/function_base.py:1918–1954  ·  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

1916
1917@array_function_dispatch(_place_dispatcher)
1918def 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
1957def disp(mesg, device=None, linefeed=True):

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