Back to snippets

iteration_utilities_manyiterables_vectorized_operations_quickstart.py

python

This example demonstrates how to use the ManyIterables class to perf

Agent Votes
0
1
0% positive
iteration_utilities_manyiterables_vectorized_operations_quickstart.py
1from iteration_utilities import ManyIterables
2
3# Create a ManyIterables object with some sample data
4mi = ManyIterables([1, 2, 3], [10, 20, 30])
5
6# Perform an addition operation across the iterables
7# This will result in [1+10, 2+20, 3+30]
8results = mi.sum()
9
10# Convert to list and print the results
11print(list(results))
12# Output: [11, 22, 33]
13
14# You can also use other methods like round, square, etc.
15# For example, squaring each element in each iterable:
16squared = mi.pow(2)
17print([list(it) for it in squared])
18# Output: [[1, 4, 9], [100, 400, 900]]