How to suppress the error message when dividing 0 by 0 using np.divide (alongside other floats)?

Mark

My attempt:

import numpy as np
np.seterr(divide='ignore')
a=np.array([4/3,0,0])
b=np.array([1,0,0])
np.divide(a,b)

The ouput I get:

__main__:1: RuntimeWarning: invalid value encountered in true_divide
array(1.33333333,        nan, nan])

If I ask it again:

np.divide(a,b)

then no RuntimeWarning is displayed.

I'm happy with the array that is output, but I don't want the error message; that is what I thought seterr would fix. How can I get rid of the warning? (I would rather not write a for loop that makes exceptions for 0/0.)

hpaulj

Try:

np.seterr(invalid='ignore')

or

np.seterr(all='ignore')

From the seterr docs:

- Invalid operation: result is not an expressible number, typically
  indicates that a NaN was produced.

1/0 produces a FloatingPointError: divide by zero encountered in true_divide error/warning.

0/0 produces a Warning: invalid value encountered in true_divide error/warning.

all will catch both.

errstate can be used to temporarily change np.seterr.

In [1472]: with np.errstate(invalid='print'):
    y=np.divide([1.2,0,0],[1,0,0])
   ......:     
Warning: invalid value encountered in true_divide

warnings are normally issued the first time the problem arise in a run, and then are silent.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to suppress infinite loop note when using "IF 0 THEN SET"

From Dev

Eliminate #Error within Report Builder 3.0 when dividing by 0

From Dev

How to show error message when the user enters only 0 or 0.0 using regular expression in Angular?

From Dev

How to eliminate "divide by 0" error in template code

From Dev

Netlogo How can I avoid the "dividing by 0" error during the dividing process compiling with Behavior space?

From Dev

How to suppress error message of a command?

From Dev

How to suppress OpenCV error message

From Dev

How to suppress the warming message by R when using commandArgs()

From Dev

Error: 0xc0000098 when dual booting Ubuntu alongside Windows 7

From Dev

Not able to suppress the error message using /dev/null

From Java

How to return 0 with divide by zero

From Dev

How to not let the user divide by 0?

From Dev

Count dividing by 0

From Dev

How to suppress certain error message in 'find' command?

From Dev

How to avoid deleting .0 on floats with NumberFormatInfo

From Dev

PHP dividing by 10, adding +1 when result is greater than .0

From Dev

tryCatch suppress error message

From Dev

Suppress error message in R

From Dev

Suppress error message in R

From Dev

Suppress 0 in the Spotfire visualization

From Dev

Display error message when user inputs "0", cannot get out of "error" message

From Dev

"Divide by zero encountered in log" when not dividing by zero

From Dev

Dividing long by long returns 0

From Dev

Dividing 2 numbers returns 0

From Dev

How to exclude 0 when using RandBetween?

From Dev

How to save integer alongside of a np.array

From Dev

How to suppress tar error messages in when piping

From Dev

How to suppress awk output when using FS?

From Dev

How to suppress PowerShell error message during variable assignment

Related Related

  1. 1

    How to suppress infinite loop note when using "IF 0 THEN SET"

  2. 2

    Eliminate #Error within Report Builder 3.0 when dividing by 0

  3. 3

    How to show error message when the user enters only 0 or 0.0 using regular expression in Angular?

  4. 4

    How to eliminate "divide by 0" error in template code

  5. 5

    Netlogo How can I avoid the "dividing by 0" error during the dividing process compiling with Behavior space?

  6. 6

    How to suppress error message of a command?

  7. 7

    How to suppress OpenCV error message

  8. 8

    How to suppress the warming message by R when using commandArgs()

  9. 9

    Error: 0xc0000098 when dual booting Ubuntu alongside Windows 7

  10. 10

    Not able to suppress the error message using /dev/null

  11. 11

    How to return 0 with divide by zero

  12. 12

    How to not let the user divide by 0?

  13. 13

    Count dividing by 0

  14. 14

    How to suppress certain error message in 'find' command?

  15. 15

    How to avoid deleting .0 on floats with NumberFormatInfo

  16. 16

    PHP dividing by 10, adding +1 when result is greater than .0

  17. 17

    tryCatch suppress error message

  18. 18

    Suppress error message in R

  19. 19

    Suppress error message in R

  20. 20

    Suppress 0 in the Spotfire visualization

  21. 21

    Display error message when user inputs "0", cannot get out of "error" message

  22. 22

    "Divide by zero encountered in log" when not dividing by zero

  23. 23

    Dividing long by long returns 0

  24. 24

    Dividing 2 numbers returns 0

  25. 25

    How to exclude 0 when using RandBetween?

  26. 26

    How to save integer alongside of a np.array

  27. 27

    How to suppress tar error messages in when piping

  28. 28

    How to suppress awk output when using FS?

  29. 29

    How to suppress PowerShell error message during variable assignment

HotTag

Archive