{"id":14347,"date":"2021-03-29T16:53:57","date_gmt":"2021-03-29T16:53:57","guid":{"rendered":"https:\/\/www.askpython.com\/?p=14347"},"modified":"2021-03-29T16:53:59","modified_gmt":"2021-03-29T16:53:59","slug":"numpy-trigonometric-functions","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python\/numpy-trigonometric-functions","title":{"rendered":"Universal NumPy Trigonometric functions to know"},"content":{"rendered":"\n<p>Hello, readers! In this article, we will learn <strong>the universal NumPy trigonometric functions<\/strong> to know! <\/p>\n\n\n\n<p>So, let us get started! \ud83d\ude42<\/p>\n\n\n\n<p>To being with, the mathematical functions in NumPy are framed as Universal functions. These Universal (mathematical NumPy functions) operate on the <a href=\"https:\/\/www.askpython.com\/python-modules\/numpy\/python-numpy-arrays\" class=\"rank-math-link\">NumPy Array class<\/a> and perform element-wise operations on the data values. The universal NumPy functions belong to the <strong>numpy.ufunc class<\/strong> in Python.<\/p>\n\n\n\n<p>In the context of this topic, we will be focusing on the below types of Universal Trigonometric functions&#8211;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Universal Trigonometric functions<\/strong><\/li><li><strong>Functions that help us perform inter-conversion between degree and radian values<\/strong><\/li><li><strong>Hyperbolic functions<\/strong><\/li><li><strong>Calculation of Hypotenuse value<\/strong><\/li><li><strong>Determining angle values from the trigonometric functions<\/strong> <\/li><\/ol>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"eh-1\"><\/span><span id=\"eh-1\"><\/span>1. Numpy Trigonometric functions<\/h2>\n\n\n\n<p>We&#8217;ll work on the following universal Numpy trigonometric functions for this tutorial&#8211;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>numpy.sin() function<\/strong>: Calculates the sine component for the array values.<\/li><li><strong>numpy.cos() function<\/strong>: Calculates the cosine component for the array values.<\/li><li><strong>numpy.tan() function<\/strong>: Calculates tangent value for the array data elements.<\/li><\/ol>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\narr = np.array(&#x5B;30,60,90])\n\nval_sin = np.sin(arr)\nprint(&quot;Sine value&quot;,val_sin)\n\nval_cos = np.cos(arr)\nprint(&quot;Cosine value&quot;,val_cos)\n\nval_tan = np.tan(arr)\nprint(&quot;Tangent value&quot;,val_tan)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nSine value &#x5B;-0.98803162 -0.30481062  0.89399666]\nCosine value &#x5B; 0.15425145 -0.95241298 -0.44807362]\nTangent value &#x5B;-6.4053312   0.32004039 -1.99520041]\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. Inter-conversion between Degree and Radian values<\/h2>\n\n\n\n<p>While performing trigonometric operations in any language, we come across situations wherein we feed the need to convert degrees to radians and vice-versa.<\/p>\n\n\n\n<p>For the same, NumPy offers us with Universal functions&#8211;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>deg2rad<\/strong>: Converts degree value of an angle to radians.<\/li><li><strong>rad2deg<\/strong>: Converts radian angle to degree.<\/li><\/ol>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\narr = np.array(&#x5B;30,60,90])\n\nrad = np.deg2rad(arr)\nprint(&quot;Radian values for the array having degree values:&quot;, rad)\n\narr_rad = np.array(&#x5B;0.52359878, 1.04719755, 1.57079633])\ndegree = np.rad2deg(arr_rad)\nprint(&quot;Degree values for the array having radian values:&quot;, degree)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nRadian values for the array having degree values: &#x5B;0.52359878 1.04719755 1.57079633]\nDegree values for the array having radian values: &#x5B;30.00000025 59.99999993 90.00000018]\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. Determining angles from the trigonometric values<\/h2>\n\n\n\n<p>In the form of reverse engineering, we now feed the below functions with trigonometric values and try to get the angle values from them&#8211;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>arcsin() function<\/strong>: Calculates the angle value from the sine values.<\/li><li><strong>arccos() function<\/strong>: Calculates the angle value from the cosine values.<\/li><li><strong>arctan() function<\/strong>: Calculates the angle value from the tangent values.<\/li><\/ol>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\narr = np.array(&#x5B;1,0.5])\n\nsin_ang = np.arcsin(arr)\nprint(&quot;Angle from the sin function:&quot;, sin_ang)\n\ncos_ang = np.arccos(arr)\nprint(&quot;Angle from the cos function:&quot;, cos_ang)\n\ntan_ang = np.arctan(arr)\nprint(&quot;Angle from the tan function:&quot;, tan_ang)\n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nAngle from the sin function: &#x5B;1.57079633 0.52359878]\nAngle from the cos function: &#x5B;0.         1.04719755]\nAngle from the tan function: &#x5B;0.78539816 0.46364761]\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"eh-4\"><\/span><span id=\"eh-4\"><\/span><span id=\"eh-4\"><\/span>4. Hypotenuse<\/h2>\n\n\n\n<p>With <strong>numpy.hypot() function<\/strong>, we can calculate the hypotenuse value according to the Pythagoras&#8217; standards by providing the function with the base and height values.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nnumpy.hypot() function\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\n\nb = 5\nh = 8\n\nhy = np.hypot(b, h)\n\nprint(hy)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n9.433981132056603\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5. Hyperbolic functions<\/h2>\n\n\n\n<p>NumPy provides us with the below functions to calculate the hyperbolic trigonometric values for the given values:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>numpy.sinh() function<\/strong>: Calculates the hyperbolic sine value for the array values.<\/li><li><strong>numpy.cosh() function<\/strong>: Calculates the hyperbolic cosine value for the array values.<\/li><li><strong>numpy.tanh() function<\/strong>: Calculates the hyperbolic tangent value for the array values.<\/li><\/ol>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\narr = np.array(&#x5B;30,60,90])\n\nval_sin = np.sinh(arr)\nprint(&quot;Hyperbolic Sine value&quot;,val_sin)\n\nval_cos = np.cosh(arr)\nprint(&quot;Hyperbolic Cosine value&quot;,val_cos)\n\nval_tan = np.tanh(arr)\nprint(&quot;Hyperbolic Tangent value&quot;,val_tan)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nHyperbolic Sine value &#x5B;5.34323729e+12 5.71003695e+25 6.10201647e+38]\nHyperbolic Cosine value &#x5B;5.34323729e+12 5.71003695e+25 6.10201647e+38]\nHyperbolic Tangent value &#x5B;1. 1. 1.]\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>By this, we have come to the end of the NumPy Trigonometric functions article. Feel free to comment below, in case you come across any questions. For more such posts related to <a href=\"https:\/\/www.askpython.com\/python\/oops\/object-oriented-programming-python\" class=\"rank-math-link\">Python programming<\/a>, Stay tuned with us!<\/p>\n\n\n\n<p>Till then, Happy Learning!! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, readers! In this article, we will learn the universal NumPy trigonometric functions to know! So, let us get started! \ud83d\ude42 To being with, the mathematical functions in NumPy are framed as Universal functions. These Universal (mathematical NumPy functions) operate on the NumPy Array class and perform element-wise operations on the data values. The universal [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":14362,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93,1],"tags":[],"class_list":["post-14347","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy","category-python"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/14347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=14347"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/14347\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/14362"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=14347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=14347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=14347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}