Skip to content

Numpy log base 2

  • by

To get Numpy log base 2, you can use numpy.log2() function. This function calculates the Base2 logarithm of x where x belongs to all the input array elements.

numpy.log2(arr, out = None, *, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None, ufunc ‘log1p’) :

This function returns a new array containing the base-2 logarithm of each element in the input array.

Numpy log base 2 example

Simple example code using the log2() function to get the logarithm of an array in NumPy.

import numpy as np

arr = np.array([2, 4, 8, 16])

result = np.log2(arr)
print(result)

Output:

Numpy log base 2

Do comment if you have any doubts or suggestions on this Python Numpy log topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading