Search code examples
pythonpython-3.xgenfromtxt

python Genfromtxt how convert negative integer in to 0


img = np.genfromtxt (path+file,dtype=int,
                invalid_raise=False,
                missing_values= (all negatives), <<<---------------
                usemask=False,
                filling_values=0)

I need catch negative integers and replace them with 0. maybe someone can write some code?


Solution

  • You can do that using .clip() as follows:

    img = img.clip(0)