
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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.
Steps
At first, import the required libraries −
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...\n",arr)
Check the Dimensions −
print("\nDimensions of our Array...\n",arr.ndim)
Get the Datatype −
print("\nDatatype of our Array object...\n",arr.dtype)
Get the Shape −
print("\nShape of our Array object...\n",arr.shape)
To compute the natural logarithm with scimath, use the np.emath.log() method in Python Numpy −
print("\nResult (log)...\n",np.emath.log(arr))
Example
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...\n",arr) # Check the Dimensions print("\nDimensions of our Array...\n",arr.ndim) # Get the Datatype print("\nDatatype of our Array object...\n",arr.dtype) # Get the Shape print("\nShape of our Array object...\n",arr.shape) # To compute the natural logarithm with scimath, use the np.emath.log() method in Python Numpy. print("\nResult (log)...\n",np.emath.log(arr))
Output
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]
Advertisements