- 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
Return the base 2 logarithm for complex value input in Python
To return the base 2 logarithm of the input array, use the numpy.log2() method in Python Numpy The method returns Base-2 logarithm of x. This is a scalar if x is a scalar. The 1st parameter, x is the input value, array-like. The 2nd parameter is out, a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
The 3rd parameter is where, the condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
Steps
At first, import the required library −
import numpy as np
Create an array using the array() method −
arr = np.array([0+1.j, 1, 2+0.j])
Display the array −
print("Array...\n", arr)
Get the type of the array −
print("\nOur Array type...\n", arr.dtype)
Get the dimensions of the Array −
print("\nOur Array Dimension...\n",arr.ndim)
Get the shape of the Array −
print("\nOur Array Shape...\n",arr.shape)
To return the base 2 logarithm of the input array, use the numpy.log2() method in Python Numpy −
print("\nResult...\n",np.log2(arr))
Example
import numpy as np # Create an array using the array() method arr = np.array([0+1.j, 1, 2+0.j]) # Display the array print("Array...\n", arr) # Get the type of the array print("\nOur Array type...\n", arr.dtype) # Get the dimensions of the Array print("\nOur Array Dimension...\n",arr.ndim) # Get the shape of the Array print("\nOur Array Shape...\n",arr.shape) # To return the base 2 logarithm of the input array, use the numpy.log2() method in Python Numpy # The method returns Base-2 logarithm of x. This is a scalar if x is a scalar. print("\nResult...\n",np.log2(arr))
Output
Array... [0.+1.j 1.+0.j 2.+0.j] Our Array type... complex128 Our Array Dimension... 1 Our Array Shape... (3,) Result... [0.+2.26618007j 0.+0.j 1.+0.j ]
- Related Articles
- Return the base 2 logarithm of the input array in Python
- Compute the Natural logarithm for complex-valued input in Python
- Return the square of the complex-value input in Python
- Return the base 10 logarithm of the input array element-wise in Numpy
- Compute the logarithm base 2 with scimath in Python
- C++ Program to calculate the base 2 logarithm of the given value
- Get the base 10 logarithm of a value in Java
- Compute the logarithm base n with scimath in Python
- Compute the logarithm base 10 with scimath in Python
- Return the natural logarithm of one plus the input array element-wise in Numpy
- How to get base 2 logarithm of E in JavaScript?
- C++ Program to calculate the base 10 logarithm of the given value
- Return the default fill value for a masked array with complex datatype in Numpy
- Logarithm of the sum of exponentiations of the inputs in base-2 in Numpy
- Return the angle of the complex argument in Python
