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 8228795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:34:57+00:00 2026-06-07T16:34:57+00:00

>>> from scipy.special import erf >>> print (erf(0.j)) __main__:1: RuntimeWarning: invalid value encountered in

  • 0
>>> from scipy.special import erf
>>> print (erf(0.j))
__main__:1: RuntimeWarning: invalid value encountered in erf
0j

This warning is only printed once (even if I do scipy.special.errprint(0)), but I don’t understand why it’s printed at all. Really, 0.j is the same number as 0. and it has no problem with that one.

I suppose there are two questions:
1) Is there any way to suppress this warning?
2) Is this warning a bug, or am I missing something?

UPDATE

I (think I) tracked down the error function in the scipy source tree. It is located in: scipy/special/specfun/specfun.f (subroutine CERROR). This function does not raise the warning (It works fine when called from a simple fortran program).

  • 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-06-07T16:34:58+00:00Added an answer on June 7, 2026 at 4:34 pm

    You can turn off warnings with numpy.seterr:

        numpy.seterr(invalid='ignore')
    

    0.j is not the same as 0.. The former is a complex number, that latter is just a float.

    >>> type(0.j)
    <class 'complex'>
    >>> type(0.)
    <class 'float'>
    

    The complex erf and real erf use different algorithms, e.g.

    >>> erf(complex(1))
    (0.84270079294971512+0j)
    >>> erf(1)
    0.84270079294971478
    

    Since the real erf and complex erf use different algorithms, some warnings in the complex erf will not be present in the real erf. If we check the Fortran implementation, we’ll find:

        SUBROUTINE CERROR(Z,CER)
    C   ...
        Z1=Z
    C   ...
        CS=Z1
        CR=Z1
        DO 10 K=1,120
            CR=CR*Z1*Z1/(K+0.5D0)
            CS=CS+CR
            IF (CDABS(CR/CS).LT.1.0D-15) GO TO 15
    10  CONTINUE
    

    In particular, Z = 0 + 0j, so Z1 = 0 + 0j, so CS = CR = 0 + 0j before the loop. At the first iteration of the loop, we get:

    • CR ← CR × Z12 / (K + 0.5) = 0 + 0j
    • CS ← CS + CR = 0 + 0j

    and then the condition requires CR/CS, which is a 0/0, which is an invalid floating point operation, and thus the warning.

    This is a minor issue which can be “fixed” easily by checking if Z == 0 at the beginning. You could report a bug if you find this behavior erratic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With this code: import scipy from scipy import * x = r_[1:15] print x
What's wrong with this snippet of code? import numpy as np from scipy import
I got some sparse matrix like this >>>import numpy as np >>>from scipy.sparse import
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
I want to use the newton function loaded as from scipy.optimize import newton in
I'm running the following Python script: #!/usr/bin/python import os,sys from scipy import stats import
I'm trying to copy the Scipy Cookbook function: from scipy import ogrid, sin, mgrid,
Is there a way to dynamically expand an scipy array from scipy import sci
from fabric.api import sudo, put, run def install(): run('source /home/user/.virtualenvs/demo/bin/activate') run('pip install requests') if
I know how to integrate a function with Scipy. I do it in this

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.