You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-77Lines changed: 2 additions & 77 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,34 +61,7 @@ When working with `Itr`, keep these points in mind:
61
61
62
62
`Itr` provides a comprehensive set of methods for various iterable operations. For a complete list of methods and their detailed descriptions, please refer to the [full documentation](autodoc.md).
63
63
64
-
*Note: The detailed list of methods in `autodoc.md` is automatically generated by [introspect.py], where `Itr` introspects itself.*
65
-
66
-
```py introspect.py
67
-
from operator import add
68
-
69
-
from itr import Itr
70
-
71
-
# use Itr to introspect itself for methods and their docstrings
72
-
methods = (
73
-
Itr(dir(Itr))
74
-
.filter(lambdam: m in ("__init__", "__iter__", "__next__") ornot m.startswith("_"))
*Note: The detailed list of methods in `autodoc.md` is automatically generated by [introspect.py](src/scripts/introspect.py), where `Itr` introspects itself.*
92
65
93
66
## Examples
94
67
@@ -163,52 +136,4 @@ For reference, an equivalent using `itertools` directly:
163
136
164
137
### More examples
165
138
166
-
More examples can be found [here](./doc/examples.md).
167
-
168
-
169
-
170
-
171
-
172
-
Beyond basic transformations, `Itr` enables powerful composition of operations, making complex data processing more manageable. This example demonstrates numerical differentiation and integration using `Itr`.
173
-
174
-
```python
175
-
from itr import Itr
176
-
import numpy as np
177
-
from operator import add
178
-
179
-
x = Itr(np.linspace(0, 1, 11))
180
-
# Need a copy of 'x' as the original 'x' is consumed in the zip method.
181
-
xy = x.copy().zip(x.map(lambdaxi: xi * xi /2))
182
-
183
-
# Numerical differentiation (central difference)
184
-
defdiff1central(xy_segment):
185
-
# Unpack the 3-element rolling window: (x0, y0), (x1, y1_ignored), (x2, y2)
186
-
(x0, y0), (x1, _y1), (x2, y2) = xy_segment
187
-
return x1, (y2 - y0) / (x2 - x0)
188
-
189
-
print("Numerical Derivatives:")
190
-
print(
191
-
xy.copy() # Need a copy as xy will be reused below for integration
192
-
.rolling(3)
193
-
.map(diff1central) # Produces (x, dy/dx) pairs
194
-
.collect()
195
-
)
196
-
197
-
# Numerical integration (trapezoidal rule)
198
-
# Integrates x**2 / 2, resulting in x**3 / 6. Over 0,1 this is 1/6.
199
-
deftrapz_accumulate(current_sum, xy_pair):
200
-
# Unpack (x0, y0) and (x1, y1) from the pairwise iteration
201
-
(x0, y0), (x1, y1) = xy_pair
202
-
return current_sum +0.5* (y0 + y1) * (x1 - x0)
203
-
204
-
print("\nNumerical Integral (Trapezoidal Rule - Fold):")
205
-
print(xy.pairwise().fold(0, trapz_accumulate))
206
-
207
-
# ...or an alternative integration implementation using starmap and flattening
0 commit comments