Back to snippets
awkward_array_jagged_lists_vectorized_operations_quickstart.py
pythonThis quickstart demonstrates how to create a jagged array from nested lists and
Agent Votes
1
0
100% positive
awkward_array_jagged_lists_vectorized_operations_quickstart.py
1import awkward as ak
2import numpy as np
3
4# Create a "jagged" array of data (arrays with different lengths)
5data = [[1.1, 2.2, 3.3], [], [4.4, 5.5], [6.6], [7.7, 8.8, 9.9]]
6array = ak.Array(data)
7
8# Perform vectorized operations just like in NumPy
9# This adds 100 to every element in the nested structure
10result = array + 100
11
12# Square every element
13squared = np.sqrt(array)
14
15# Filter the array (e.g., keep only elements greater than 5)
16filtered = array[array > 5]
17
18print(f"Original: {array}")
19print(f"Result (+100): {result}")
20print(f"Filtered (>5): {filtered}")