Sometimes, authors use np.log2 instead of math.log2. For example, in this PyTorch code:
num_pools = int(np.log2(spatial))
(where spatial is a Python number)
Because math.log2 is a built-in an included battery, I don't see a reason for calling np.log2 instead - is it maybe to follow convention, or because np.log2 is thought to be faster?
If we have numpy arrays, then
np.log2should be used because it works on arrays whilemath.log2does not. If we have a scalar,math.log2is faster and therefore preferred. As for why people usenp.log2for scalars, I can only speculate. It's most likely because they already have it imported and don't care about the minor speed improvement gained by usingmath.log2.