I am working with Python 3.6.I'm really confused, why did this happen?
In [1]: import numpy as np In [2]: a = np.array(-1) In [3]: a Out[3]: array(-1) In [4]: a ** (1/3) /Users/wonderful/anaconda/bin/ipython:1: RuntimeWarning: invalid value encountered in power #!/Users/wonderful/anaconda/bin/python Out[4]: nan
Numpy does not seem to allow fractional powers of negative numbers, even if the power does not lead to a complex number. (I actually had the same problem earlier today, unrelated). One way is to use
np.sign(a) * (np.abs(a)) ** (1 / 3)
change dtype to complex numbers
a = np.array(-1, dtype=np.complex)
The problem arises when you work with the roots of negative numbers.
Source: https://habr.com/ru/post/1694240/More articles:Почему в Chrome Dev Console появляется сообщение об ошибке "Неотдача ReferenceError: $не определена"? - javascriptWhat is the use of the logOnly parameter in ngrx DevTools? - angularIn Python 3.6, why does a negative number to the degree of a fraction return nan when in a numpy array? - pythonintbitset __init__ calls SIGSEGV - pythonCodeigniter Pagination Infinite Scroll с использованием Ajax и JQuery, дающий только повторяющиеся данные - javascriptwhat is required ('.') used in node.js - javascriptFabric / Crashlytics - only the first line of a logged message is visible in the details of the problem - iosSpringBoot hibernate gradle byte code improvement - spring-bootHow to configure Hibernate Gradle plugin to improve bytecode? - hibernateHow do I enable Hibernate bytecode acceleration before running Intellij IDEA? - javaAll Articles