To get Numpy log base 2, you can use numpy.log2() function. This function calculates the Base–2 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)
Do comment if you have any doubts or suggestions on this Python Numpy log topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.