• jQuery
  • Java IO
  • Struts
  • RubyonRails
  • Core Java
  • SQL Tutorial
  • Spring
  • JSP
  • JavaScript

  • <

    Numpy Mathematical Functions

    NumPy contains a large number of various mathematical operations. NumPy provides standard trigonometric functions, functions for arithmetic operations, handling complex numbers, etc.


    Numpy Trigonometric functions

    NumPy has standard trigonometric functions which return trigonometric ratios for a given angle in radians.


    
    import numpy as np  
    arr = np.array([0, 30, 60, 90, 120, 150, 180])  
    print("\nThe sin value of the angles",end = " ")  
    print(np.sin(arr * np.pi/180))  
    print("\nThe cosine value of the angles",end = " ")  
    print(np.cos(arr * np.pi/180))  
    print("\nThe tangent value of the angles",end = " ")  
    print(np.tan(arr * np.pi/180))  
    

    output
    
    The sin value of the angles 
    [0.00000000e+00 5.00000000e-01 8.66025404e-01 1.00000000e+00
     8.66025404e-01 5.00000000e-01 1.22464680e-16]
    
    The cosine value of the angles 
    [ 1.00000000e+00  8.66025404e-01  5.00000000e-01  6.12323400e-17
     -5.00000000e-01 -8.66025404e-01 -1.00000000e+00]
    
    The tangent value of the angles [ 0.00000000e+00  5.77350269e-01  1.73205081e+00  1.63312394e+16
     -1.73205081e+00 -5.77350269e-01 -1.22464680e-16]
    


    numpy.around() function

    This is a function that returns the value rounded to the desired precision.


    import numpy as np  
    arr = np.array([12.202, 90.23120, 123.020, 23.202])  
    print("printing the original array values:",end = " ")  
    print(arr)  
    print("Array values rounded off to 2 decimal position",np.around(arr, 2))  
    print("Array values rounded off to -1 decimal position",np.around(arr, -1))  
    
    

    output
    
    printing the original array values: [ 12.202   90.2312 123.02    23.202 ]
    Array values rounded off to 2 decimal position [ 12.2   90.23 123.02  23.2 ]
    Array values rounded off to -2 decimal position [ 10.  90. 120.  20.]
    


    numpy.floor() function

    This function is used to return the floor value of the input data which is the largest integer not greater than the input value.


    import numpy as np  
    arr = np.array([12.202, 90.23120, 123.020, 23.202])  
    print(np.floor(arr))  
    
    
    

    output
    
    [ 12.  90. 123.  23.]
    
    


    numpy.ceil() function

    The ceil() function returns the ceiling of an input value,


    import numpy as np  
    arr = np.array([12.202, 90.23120, 123.020, 23.202])  
    print(np.ceil(arr))  
    
    

    output
    
    [ 13.  91. 124.  24.]
    
    
















    © copyright 2017-2021 Completedone pvt ltd.