cbrt()#
relationalai.std.math
#cbrt(value: Number|Producer) -> Expression
Calculates the cube root of value
.
If value
is a Producer
, cbrt()
acts as a filter and removes any non-numeric values from the producer.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
value | Producer or Python Number object | The number to take the cube root of. |
Returns#
An Expression
object.
Example#
Use cbrt()
to calculate the cube root of a number:
#import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Account = model.Type("Account")
with model.rule():
Account.add(id=1).set(balance=27.0)
Account.add(id=2).set(balance=-64.0) # Negative balance
Account.add(id=3).set(balance="INVALID") # Non-numeric balance
# =======
# EXAMPLE
# =======
# Set a balance_cbrt property to the cube root of each account's balance.
with model.rule():
account = Account()
account.set(balance_cbrt=math.cbrt(account.balance))
# Since cbrt() filters out non-numeric values, the balance_cbrt
# property is not set for the account with ID 3.
with model.query() as select:
account = Account()
response = select(account.id, account.balance_cbrt)
print(response.results)
# id balance_cbrt
# 0 1 3.0
# 1 2 -4.0
# 2 3 NaN