- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- 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 logarithm base n with scimath in Python

To compute the logarithm base n with scimath, use the scimath.logn() method in Python Numpy. The method returns the log base n of the x value(s). If x was a scalar, so is out, otherwise an array is returned.

If x contains negative inputs, the answer is computed and returned in the complex domain. The 1st parameter, n is the integer base(s) in which the log is taken. The 2nd parameter, x is the value(s) whose log base n 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([-4, -8, 8])

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 logarithm base n with scimath, use the scimath.logn() method in Python Numpy. The method returns the log base n of the x value(s). If x was a scalar, so is out, otherwise an array is returned −

print("\nResult (logn)...\n",np.emath.logn(2, arr))

## Example

import numpy as np # Creating a numpy array using the array() method arr = np.array([-4, -8, 8]) # 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 logarithm base n with scimath, use the scimath.logn() method in Python Numpy # The method returns the log base n of the x value(s). If x was a scalar, so is out, otherwise an array is returned. print("\nResult (logn)...\n",np.emath.logn(2, arr))

## Output

Our Array... [-4 -8 8] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result (logn)... [2.+4.53236014j 3.+4.53236014j 3.+0.j ]

- Related Articles
- Compute the logarithm base 2 with scimath in Python
- Compute the logarithm base 10 with scimath in Python
- Compute the natural logarithm with scimath 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 Natural Logarithm in Python
- Compute the square root of complex inputs with scimath in Python
- Compute the Natural logarithm for complex-valued input in Python
- Return the base 2 logarithm of the input array in Python
- Return the base 2 logarithm for complex value input in Python
- Compute the sign and natural logarithm of the determinant of an array in Python
- Get the base 10 logarithm of a value in Java
- How to compute the Logarithm of elements of a tensor in PyTorch?
- Compute the inverse of an N-dimensional array in Python