TypeError: unsupported operand type(s) for ^: 'numpy.float64' and 'numpy.float64'

Mlle Blanche

I just started programming in Python and am very new to Numpy packages... I'm still trying to get a hang of it. I am trying to slove a function with the euler method.

Here is my code:

Z=4
B=8
U=1
C=4

a,b=(0.0,10.0)
n=2000
x0=-1.0
t=linspace (a,b,n)
#-----------------------------------------------------------------------------
def euler (f,x0,t):
    n=len (t)
    x=np.array(n*[x0,])
    for i in xrange (n-1):
        float (x[i] + ( t[i+1] - t[i] ) * f( x[i], t[i] ))
    return x



#---------------------------------------------------------------------------------          
if __name__=="__main__":


    def f(x,t): 
        return float((Z)*[-(1/6)*B*C*x^3+0.5*U*t^2])


    #numerical solutions
    x_euler=euler(f,x0,t)


    #figure
    plt.plot (t,x_euler, "b")
    xlabel (t)
    ylabel (x)
    legend ("Euler")

    show()

I do not get along with the similar solutions for such problems. Here is my Traceback:

Traceback (most recent call last):
  File "C:\Python27\testeuler.py", line 45, in <module>
    x_euler=euler(f,x0,t)
  File "C:\Python27\testeuler.py", line 31, in euler
    float (x[i] + ( t[i+1] - t[i] ) * f( x[i], t[i] ))
  File "C:\Python27\testeuler.py", line 41, in f
    return float((Z)*[-(1/6)*B*C*x^3+0.5*U*t^2])
TypeError: unsupported operand type(s) for ^: 'numpy.float64' and 'numpy.float64'

Anyone know what could be wrong or have any suggestions?

Kevin

The caret operator (^) is not exponentiation. It is bitwise XOR, which only makes sense for integers. You want ** instead.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Numpy float64 vs Python float

From Dev

numpy.polyfit shows TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'float'

From Dev

How to convert a numpy array from 'float64' to 'float'

From Dev

float32 representation to float64 NumPy Python

From Dev

Numpy casting float32 to float64

From Dev

Why is numpy.dtype('float64') special?

From Dev

Why does numpy integer subtraction produce a float64?

From Dev

Convert float64 numpy array to floats not in scientific notation

From Dev

Does Qt5 accept Numpy float64?

From Dev

unsupported operand types for * : 'float' and 'decimal'

From Dev

Numpy.dot TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'

From Dev

Convert numpy array type and values from Float64 to Float32

From Dev

2D numpy array doesn't implicitly convert from int64 to float64

From Dev

TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

From Dev

TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

From Dev

TypeError: unsupported operand type(s) for -: 'float' and 'method'

From Dev

TypeError: unsupported operand type(s) for /: 'float' and 'instancemethod'

From Dev

TypeError: unsupported operand type(s) for -: 'instance' and 'float'

From Dev

TypeError: unsupported operand type(s) for <<: 'int' and 'float'

From Dev

TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'

From Dev

TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

From Dev

Scipy hstack results in "TypeError: no supported conversion for types: (dtype('float64'), dtype('O'))"

From Dev

TypeError: unsupported operand type(s) for -: 'str' and 'numpy.ndarray'

From Dev

strange behavior: apparently a numpy nan in a pandas dataframe showing up as dtype('float64')

From Dev

TypeError: 'numpy.float64' object is not callable?

From Dev

TypeError: 'numpy.float64' object is not callable?

From Dev

NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?

From Dev

TypeError: unsupported operand type(s) for &: 'float' and 'float', but I have no &

From Dev

Python TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

Related Related

  1. 1

    Numpy float64 vs Python float

  2. 2

    numpy.polyfit shows TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'float'

  3. 3

    How to convert a numpy array from 'float64' to 'float'

  4. 4

    float32 representation to float64 NumPy Python

  5. 5

    Numpy casting float32 to float64

  6. 6

    Why is numpy.dtype('float64') special?

  7. 7

    Why does numpy integer subtraction produce a float64?

  8. 8

    Convert float64 numpy array to floats not in scientific notation

  9. 9

    Does Qt5 accept Numpy float64?

  10. 10

    unsupported operand types for * : 'float' and 'decimal'

  11. 11

    Numpy.dot TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'

  12. 12

    Convert numpy array type and values from Float64 to Float32

  13. 13

    2D numpy array doesn't implicitly convert from int64 to float64

  14. 14

    TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

  15. 15

    TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

  16. 16

    TypeError: unsupported operand type(s) for -: 'float' and 'method'

  17. 17

    TypeError: unsupported operand type(s) for /: 'float' and 'instancemethod'

  18. 18

    TypeError: unsupported operand type(s) for -: 'instance' and 'float'

  19. 19

    TypeError: unsupported operand type(s) for <<: 'int' and 'float'

  20. 20

    TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'

  21. 21

    TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

  22. 22

    Scipy hstack results in "TypeError: no supported conversion for types: (dtype('float64'), dtype('O'))"

  23. 23

    TypeError: unsupported operand type(s) for -: 'str' and 'numpy.ndarray'

  24. 24

    strange behavior: apparently a numpy nan in a pandas dataframe showing up as dtype('float64')

  25. 25

    TypeError: 'numpy.float64' object is not callable?

  26. 26

    TypeError: 'numpy.float64' object is not callable?

  27. 27

    NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?

  28. 28

    TypeError: unsupported operand type(s) for &: 'float' and 'float', but I have no &

  29. 29

    Python TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

HotTag

Archive