0

I have a numpy array size of MxN and a threshold value T. A formula is defined as a_ij = min(a_ij, T), for all a_ij in array A_(MxN)

It means that the threshold T will cut the value of the array A in low bound. Do we have any function in python to do it? I used np.min but it returned a number instead of an array

For example

A =[[1,2],[3,4]]
T=2
A_cut = min(A,T) = [[1,2],[2,2]]
DYZ
  • 55,249
  • 10
  • 64
  • 93
Moon Lee
  • 385
  • 5
  • 18
  • 1
    You can use `numpy.clip` – pault Jan 15 '19 at 16:48
  • 1
    Possible duplicate of [numpy replace negative values in array](https://stackoverflow.com/questions/10335090/numpy-replace-negative-values-in-array) or [Replace all elements of Python NumPy Array that are greater than some value](https://stackoverflow.com/questions/19666626/replace-all-elements-of-python-numpy-array-that-are-greater-than-some-value) or [Forcing Elements in a Numpy Array to be Within a Specified Range](https://stackoverflow.com/questions/7035175/forcing-elements-in-a-numpy-array-to-be-within-a-specified-range) – pault Jan 15 '19 at 16:49

1 Answers1

3
np.minimum(A, T)
#array([[1,2], [2,2]])
DYZ
  • 55,249
  • 10
  • 64
  • 93