Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
i have this problem with my Python code :
from math import *
m = pow(complex(1,2)*complex(3,0) + complex(1,0),complex(-1,0));
TypeError: can't convert complex to float
Does anyone know how to solve this problem ?
Thanks a lot !
The problem is that you are using from math import *. This shadows the built-in pow with a version that doesn't support complex numbers.
>>> pow(1+1j, 1)
(1+1j)
>>> import math
>>> math.pow(1+1j,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
from <x> import * is usually considered bad practice, and cases like this are why.
Instead, you should use import math, and reference all your math functions as, e.g. math.sqrt
Alternatively, you can use ** instead of pow:
>>> 1j ** 2
(-1+0j)
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm having a similar issue as to this post:
Why does this simple numpy multiply operation raise an "invalid number of arguments" error?
I have this incredibly confusing equation in my code:
(m[0]*np.power(q[0])*q[0]*r[0]*(m[0]*R)*np.power(q[0]))/(R*((m[0]*R)*np.power(q[0])+m*np.power(q[0]))**2) - a[0]*N/(b[0]+N)
and when I run it, it returns the error:
ValueError: invalid number of arguments
I assumed it could have something to do with the ** I was using to define the exponents (q[0] is an exponent), so I substituted those to np.power() to no success. Also, I changed the / that I am using to define the fractions to *(.....)**(-1), but that didn't work either. At this point, I'm assuming the issue is with the * I'm using for multiplications. But how can I write multiplications and divisions in this long expression without raising a position error?
Thank you in advance for the help!
You have to add another argument of what power you want.
For example, power means add 2
For example, cube means add 3
np.power(x1, 2)
np.power(x1, 3)
If you just want to squre with np.power(), then I have already edited the code for you:
(m[0]*np.power(q[0], 2)*q[0]*r[0]*(m[0]*R)*np.power(q[0], 2))/(R*((m[0]*R)*np.power(q[0], 2)+m*np.power(q[0], 2))**2) - a[0]*N/(b[0]+N)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I write code which will output some data file, but I got error and have no idea what is wrong already looking for 2 hours (you know how is it :) )
import binascii
import sys
import time
url12 = "my win dir for file"
def toHex(s):
1st = []
for ch in s:
hv = hex(ord(ch)).replace('0x', '')
if len(hv) == 1:
1st.append(hv)
return reduce(lambda x,y:x+y, 1st)
url = toHex(url12)
.......etc.
debug output:
Traceback (most recent call last):
File "C:\Users\RED\Desktop\builder\builderUpdate.py", line 22, in <module>
url = toHex(url12)
File "C:\Users\RED\Desktop\builder\builderUpdate.py", line 20, in toHex
return reduce(lambda x,y:x+y, lst)
NameError: name 'reduce' is not defined
In Python 2, reduce was a built-in function. In Python 3, you have to import it from functools
That's why you're getting an error
Also, the empty list in your function can't begin with a number otherwise you get a syntax error. It can contain numbers but should start with an underscore or a letter
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So basically I have to write a code which tells the user to input numbers (as variables I named them number1, number2, number3 ...) until I get the answer of zero once you add each number that they inputted then which the sum is equal to zero I should print how many numbers they inputted so the answer they got was zero, now the main thing is that I know how to write that code but there is an error that I get:
Traceback (most recent call last):
File "Solution.py", line 13, in <module>
sys.exit()
NameError: name 'sys' is not defined
Maybe try using
from sys import *
and just use exit(0) when you want to sys.exit()
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Can't understand the error in this as the brackets are as per directions
mean=df["Normalized-losses"].mean()
Traceback (most recent call last):
File "C:\Users\Aarushi Goyal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\nanops.py", line 822, in _ensure_numeric
x = float(x)
Please provide solution
Try converting the column into numeric using
pd.to_numeric(df['Normalized-losses'], errors = 'coerce')
Then try:
mean = df['Normalized-losses'].mean()
You can also use:
mean = df.loc[:, 'Normalized-losses'].mean()
If it doesn't help do provide more info regarding the error.
I think the variable "Normalized-losses" would be a non-numerical type variable.
Try pandas dtypes method to check data type:
df.dtypes
If its non-numerical then use astype() method to change the data type.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am new to python and my problem is when I want to make a calculator that calculates the volume of a cube:
>>> print(int ** 3 (input ("Enter the side length: ")))
Enter the side length: 4
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
print(int ** 3 (input ("Enter the side length: ")))
TypeError: 'int' object is not callable
The int() function should wrap around the whole input() function, Something like this
print(int(input('Enter the side length:')) ** 3)