# 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 ]