Skip to content

relationalai.std.math.log10()

log10(value: Number|Producer) -> Expression

Calculates the base-10 logarithm of value. If value is a Producer, log10() filters out any non-numeric or negative values from the producer. Must be called in a rule or query context.

NameTypeDescription
valueProducer or Python Number objectThe number to take the base-10 logarithm of.

An Expression object.

Use log10() to calculate the base-10 logarithm of a number:

import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Person = model.Type("Person")
with model.rule():
Person.add(id=1).set(name="Alice", age=100)
Person.add(id=2).set(name="Bob", age=-10) # Negative age
Person.add(id=3).set(name="Carol", age="INVALID") # Non-numeric age
# =======
# EXAMPLE
# =======
# Set an age_log10 property to the base-10 logarithm of each person’s age.
with model.rule():
person = Person()
person.set(age_log10=math.log10(person.age))
# Since log10() filters out negative and non-numeric values, the age_log10
# property is not set for Bob or Carol.
with model.query() as select:
person = Person()
response = select(person.id, person.name, person.age_log10)
print(response.results)
# id name age_log10
# 0 1 Alice 2.0
# 1 2 Bob NaN
# 2 3 Carol NaN