Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7218767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:31:37+00:00 2026-05-28T21:31:37+00:00

I am doing some simple math recessively in a python script and am getting

  • 0

I am doing some simple math recessively in a python script and am getting the follow warning:

“Warning: divide by zero encountered in divide”.

To provide some context, I am taking two values and trying to find the percent difference in value (a - b) / a and if its above a certain range then process it, but sometimes the value of a or b is zero.

I want to get rid of this specific warning (at a specific line) but all the information I have found so far seems to show me how to stop all warnings (which I do not want).

When I used to write shell scripts, I could do something like this

code...
more code 2 > error.txt
even more code  

In that example, I would get the warnings for the ‘code’ and ‘even more code’ command but not for the second line.

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:31:38+00:00Added an answer on May 28, 2026 at 9:31 pm

    I’d avoid the division-by-zero in the first place:

    if a == 0:
        # Break out early
    
    # Otherwise the ratio makes sense
    

    If you do want to squash that particular numpy warning on a single line, numpy provides a way:

    with numpy.errstate(divide='ignore'):
        # The problematic line
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some really simple math and saving the result to a MS SQL2008
I would like to do some simple math while I'm doing string formatting. For
I am doing some simple sanity validation on various types. The current test I'm
I'm doing some simple tests (in preparation for a larger project) to call an
I'm doing some fairly simple cross-platform TCP socket programming. I have unfortunately found out
What am I doing wrong here: class Helo { // main: generate some simple
While doing some random experimentation with a factorial program in C, Python and Scheme.
I'm doing some simple client side validation with jQuery. var passedValidation = new Boolean(true);
I expected this to be simple, but I'm getting some strange results. I'd appreciate
I'm doing some simple MS unit tests on my standard, nothing special controller. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.