#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Numpy sin function incorrect?


    Having trouble with numpy.sin() function. It seems to be returning incorrect values.

    Code:
    import numpy as np
    import pylab
    
    x = np.sin(2/3) #np.exp(-0.1*t)*
    x
    This outputs:
    0.0

    Which is incorrect it should be 0.6183698

    Any ideas why the basic sin function is not outputting the correct result?

    Even if it was for some reason processing this as a degree it should output: 0.01163527

    I am stumped but this error is repeated in other scripts that rely on correct sin calculations.

    thanks for your help.

    It seems to do this for all fractions. What gives?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    430
    Rep Power
    66
    Code:
    x = np.sin(2/3) #np.exp(-0.1*t)*
    You are using integer arithmetic (in Python 2). Try 2/3.0.
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (mini laptop, work laptop), Android 4.2.1 (tablet)

IMN logo majestic logo threadwatch logo seochat tools logo