Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reciprocal of complex 0 and 1 / numpy.array(0+0j) give different results #17425

Open
@kurtamohler

Description

@kurtamohler

numpy.reciprocal(a) and 1 / a give different results with a = numpy.array(0 + 0j). reciprocal gives nan+nanj, and 1 / a gives inf+nanj.

It seems like neither of these results is correct, but I could certainly be wrong. I feel like the result in both cases should be inf+0j, since we get inf when we use real numbers: 1 / numpy.array(0.0) and numpy.reciprocal(numpy.array(0.0)).

Reproducing code example:

>>> import numpy

>>> a = numpy.array(0 + 0j)
__main__:1: RuntimeWarning: invalid value encountered in reciprocal
>>> numpy.reciprocal(a)
(nan+nanj)
>>> 1 / a
(inf+nanj)

>>> 1 / numpy.array(0.0)
inf
>>> numpy.reciprocal(numpy.array(0.0))
__main__:1: RuntimeWarning: divide by zero encountered in reciprocal
inf

NumPy/Python version information:

>>> print(numpy.__version__, sys.version)
1.18.1 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0]

OS

Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions