Hi again,
Thanks for your input; I'm starting to use generators to some extent.
Say we have a series of numbers:
x = randn(100)
and values beyond some criteria should be considered as outliers, but
only where there's at most 3 (or some other integer) consecutive values
beyond the criteria. The
Ian Kelly wrote:
> On Wed, Dec 24, 2014 at 1:34 PM, Rustom Mody
> wrote:
>> +1 for the slice in succinct form
>
> Not only more succinct but also more correct. The purpose of islice is to
> slice arbitrary iterables as opposed to just sequences. But this function
> requires a reentrant iterable
On Wed, Dec 24, 2014 at 1:34 PM, Rustom Mody wrote:
> +1 for the slice in succinct form
Not only more succinct but also more correct. The purpose of islice is to
slice arbitrary iterables as opposed to just sequences. But this function
requires a reentrant iterable anyway and returns garbage if y
On Wednesday, December 24, 2014 8:42:32 PM UTC+5:30, Vito De Tullio wrote:
> Seb wrote:
>
> def n_grams(a, n):
> > ... z = (islice(a, i, None) for i in range(n))
> > ... return zip(*z)
> > ...
> >
> > I'm impressed at how succinctly this islice helps to build a list of
> > tuples wit
Terry Reedy writes:
> On 12/23/2014 4:25 PM, Ben Finney wrote:
> > To be clear: there's nothing about parentheses that produce a
> > generator expression.
>
> Incorrect; parentheses *are* as a part of 'generator expression'.
> From the doc:
> generator_expression ::= "(" expression comp_for ")"
Seb wrote:
def n_grams(a, n):
> ... z = (islice(a, i, None) for i in range(n))
> ... return zip(*z)
> ...
>
> I'm impressed at how succinctly this islice helps to build a list of
> tuples with indices for all the required windows.
If you want it succinctly, there is this variation o
On 12/23/2014 4:25 PM, Ben Finney wrote:
Ian Kelly writes:
On Tue, Dec 23, 2014 at 11:55 AM, Seb wrote:
Particulary, what do the parentheses do there?
The parentheses enclose a generator expression, which is similar to a
list comprehension [1] but produce a generator, which is a type of
it
Ian Kelly writes:
> On Tue, Dec 23, 2014 at 11:55 AM, Seb wrote:
> > Particulary, what do the parentheses do there?
>
> The parentheses enclose a generator expression, which is similar to a
> list comprehension [1] but produce a generator, which is a type of
> iterator, rather than a list.
To b
On 12/23/2014 1:55 PM, Seb wrote:
def n_grams(a, n):
... z = (islice(a, i, None) for i in range(n))
... return zip(*z)
I'm impressed at how succinctly this islice helps to build a list of
tuples with indices for all the required windows. However, I'm not
quite following what goes on
On Tue, 23 Dec 2014 12:23:45 -0700,
Ian Kelly wrote:
> The parentheses enclose a generator expression, which is similar to a
> list comprehension [1] but produce a generator, which is a type of
> iterator, rather than a list.
> In much the same way that a list comprehension can be expanded out t
On Tue, Dec 23, 2014 at 11:55 AM, Seb wrote:
>
> Hi,
>
> I'm fairly new to Python, and while trying to implement a custom sliding
> window operation for a pandas Series, I came across a great piece of
> codeĀ¹:
>
> >>> def n_grams(a, n):
> ... z = (islice(a, i, None) for i in range(n))
> ...
Hi,
I'm fairly new to Python, and while trying to implement a custom sliding
window operation for a pandas Series, I came across a great piece of
codeĀ¹:
>>> def n_grams(a, n):
... z = (islice(a, i, None) for i in range(n))
... return zip(*z)
...
I'm impressed at how succinctly this islic
12 matches
Mail list logo