🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to NumPy Notes
Topic #36

ufunc Logs


Logs

NumPy provides functions to perform log at the base 2, e and 10.

We will also explore how we can take log for any base by creating a custom ufunc.

All of the log functions will place -inf or inf in the elements if the log can not be computed.


Log at Base 2

Use the log2() function to perform log at the base 2.

Example

  import numpy as np

arr = np.arange(1, 10)

print(np.log2(arr))

Note: The arange(1, 10) function returns an array with integers starting from 1 (included) to 10 (not included).


Log at Base 10

Use the log10() function to perform log at the base 10.

Example

  import numpy as np

arr = np.arange(1, 10)

print(np.log10(arr))

Natural Log, or Log at Base e

Use the log() function to perform log at the base e.

Example

  import numpy as np

arr = np.arange(1, 10)

print(np.log(arr))

Log at Any Base

NumPy does not provide any function to take log at any base, so we can use the frompyfunc() function along with inbuilt function math.log() with two input parameters and one output parameter:

Example

  from math import log
import numpy as np

nplog = np.frompyfunc(log,
  2, 1)

print(nplog(100, 15))

Want to go beyond the notes?

Join CodingNow 2.0's NumPy course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

ufunc Logs – FAQs

Quick answers about learning ufunc Logs in NumPy.

This free note from CodingNow 2.0 explains ufunc Logs in NumPy — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every NumPy topic on CodingNow 2.0, including ufunc Logs, is 100% free with no signup required.
With focused practice, most students grasp ufunc Logs in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now