log()

Calculates the natural logarithm (the base-e logarithm) of a number.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def setup():
  i = 12
  py5.println(py5.log(i))
  py5.println(log10(i))

  j = -5
  py5.println(py5.log(j))

# Calculates the base-10 logarithm of a number
# use this if you don't want to use numpy's log10 function
def log10(x):
    return (py5.log(x) / py5.log(10))

Description

Calculates the natural logarithm (the base-e logarithm) of a number. This function expects the n parameter to be a value greater than 0.0. This function is the compliment to exp().

This function makes a call to the numpy log() function. If the n parameter is less than or equal to 0.0, you will see a RuntimeWarning and the returned result will be numpy’s Not-a-Number value, np.nan.

Syntax

log(value: float) -> float

Parameters

  • value: float - number greater than 0.0

Updated on September 11, 2021 16:51:34pm UTC