Data Operations¶
These functions extract, filter, transform, and aggregate data.
get¶
Extracts a single field from a record or structured data object.
Parameters:
data- A record or structured data objectfield- A string specifying the field name
Returns: The value of the specified field.
let response = query_model(my_model, "Is AI safe?", {"topic": "safety"});
let answer = get(response, "value");
get_all¶
Extracts a field from each element in a list of records.
Parameters:
data- A list of recordsfield- A string specifying the field name to extract
Returns: A list of values, one from each record.
let responses = [
{"value": "yes", "confidence": 0.9},
{"value": "no", "confidence": 0.6},
{"value": "yes", "confidence": 0.8}
];
let values = get_all(responses, "value");
// values = ["yes", "no", "yes"]
filter_by_key¶
Filters a list of records, keeping only those where the specified field matches the given value.
Parameters:
data- A list of recordskey- A string specifying the field name to filter onvalue- The value to match against
Returns: A filtered list of records.
flatten¶
Flattens a multi-dimensional array into a one-dimensional array.
Parameters:
array- An array (possibly multi-dimensional)
Returns: A flat one-dimensional array.
argmax¶
Returns the index of the maximum value for each element in the array. For multi-class probability arrays, this returns the predicted class label.
Parameters:
array- An array of values or an array of probability arrays
Returns: An array of indices.
convert_to_one_hot¶
Converts an array of probability distributions to one-hot encoded vectors.
Parameters:
array- An array of probability arrays
Returns: An array of one-hot vectors where only the maximum probability index is 1.
fill¶
Creates an array of a specified length filled with a single value.
Parameters:
value- The value to repeatlength- The number of elements
Returns: An array of the given length.
sum¶
Computes the sum of all elements in a list.
Parameters:
list- A list of numbers
Returns: The sum.
size¶
Returns the number of elements in a list.
Parameters:
list- A list
Returns: The length as an integer.
histogram¶
Computes a frequency distribution of answers grouped by question.
Parameters:
data- A list of recordsquestion_field- The field name containing the question identifieranswer_field- The field name containing the answer value
Returns: A record mapping questions to answer frequency distributions.
box_plot¶
Computes box plot statistics grouped by question and answer.
Parameters:
data- A list of recordsquestion_field- The field name for question groupinganswer_field- The field name for answer groupingscore_field- The field name containing numeric scores
Returns: A list of records with box plot statistics (min, max, median, quartiles) for each group.