

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compute the natural logarithm with scimath in Python
<p>To compute the natural logarithm with scimath, use the np.emath.log() method in Python Numpy. The method returns the log of the x value(s). If x was a scalar, so is out, otherwise an array is returned. The 1st parameter, x is the value(s) whose log is (are) required.</p><h2>Steps</h2><p>At first, import the required libraries −</p><pre class="just-code notranslate language-numpy" data-lang="numpy">import numpy as np</pre><p>Creating a numpy array using the array() method −</p><pre class="just-code notranslate language-numpy" data-lang="numpy">arr = np.array([np.inf, -np.inf, np.exp(1), -np.exp(1)]) </pre><p>Display the array −</p><pre class="just-code notranslate language-numpy" data-lang="numpy">print("Our Array... ",arr)</pre><p>Check the Dimensions −</p><pre class="just-code notranslate language-numpy" data-lang="numpy">print(" Dimensions of our Array... ",arr.ndim) </pre><p>Get the Datatype −</p><pre class="just-code notranslate language-numpy" data-lang="numpy">print(" Datatype of our Array object... ",arr.dtype)</pre><p>Get the Shape −</p><pre class="just-code notranslate language-numpy" data-lang="numpy">print(" Shape of our Array object... ",arr.shape) </pre><p>To compute the natural logarithm with scimath, use the np.emath.log() method in Python Numpy −</p><pre class="just-code notranslate language-numpy" data-lang="numpy">print(" Result (log)... ",np.emath.log(arr))</pre><h2>Example</h2><pre class="demo-code notranslate language-numpy" data-lang="numpy">import numpy as np # Creating a numpy array using the array() method arr = np.array([np.inf, -np.inf, np.exp(1), -np.exp(1)]) # Display the array print("Our Array... ",arr) # Check the Dimensions print(" Dimensions of our Array... ",arr.ndim) # Get the Datatype print(" Datatype of our Array object... ",arr.dtype) # Get the Shape print(" Shape of our Array object... ",arr.shape) # To compute the natural logarithm with scimath, use the np.emath.log() method in Python Numpy. print(" Result (log)... ",np.emath.log(arr))</pre><h2>Output</h2><pre class="result notranslate">Our Array... [ inf -inf 2.71828183 -2.71828183] Dimensions of our Array... 1 Datatype of our Array object... float64 Shape of our Array object... (4,) Result (log)... [inf+0.j inf+3.14159265j 1.+0.j 1.+3.14159265j]</pre>
- Related Questions & Answers
- Compute the logarithm base 2 with scimath in Python
- Compute the logarithm base n with scimath in Python
- Compute the logarithm base 10 with scimath in Python
- Compute the Natural Logarithm in Python
- Compute the Natural logarithm for complex-valued input in Python
- Compute the inverse cosine with scimath in Python
- Compute the inverse sine with scimath in Python
- Compute the inverse hyperbolic tangent with scimath in Python
- Compute the sign and natural logarithm of the determinant of an array in Python
- Compute the square root of complex inputs with scimath in Python
- Get natural logarithm value using Math.log in Java
- How to get Natural logarithm of 2 in JavaScript?
- How to get Natural logarithm of 10 in JavaScript?
- How to compute the Logarithm of elements of a tensor in PyTorch?
- Return the natural logarithm of one plus the input array element-wise in Numpy
Advertisements