Il giorno lunedì 20 marzo 2023 alle 19:10:26 UTC+1 Thomas Passin ha scritto:
> On 3/20/2023 11:21 AM, Edmondo Giovannozzi wrote:
> >
> >>> def sum1():
> >>> s = 0
> >>> for i in range(100):
> >>> s += i
> >>> return s
> >>>
> >>> def sum2():
> >>> return sum(range(100))
> >> Here
On 3/20/2023 11:21 AM, Edmondo Giovannozzi wrote:
def sum1():
s = 0
for i in range(100):
s += i
return s
def sum2():
return sum(range(100))
Here you already have the numbers you want to add.
Actually using numpy you'll be much faster in this case:
§ imp
On 2023-03-20 15:21, Edmondo Giovannozzi wrote:
> def sum1():
> s = 0
> for i in range(100):
> s += i
> return s
>
> def sum2():
> return sum(range(100))
Here you already have the numbers you want to add.
Actually using numpy you'll be much faster in thi
> > def sum1():
> > s = 0
> > for i in range(100):
> > s += i
> > return s
> >
> > def sum2():
> > return sum(range(100))
> Here you already have the numbers you want to add.
Actually using numpy you'll be much faster in this case:
§ import numpy as np
§ d
On 2023-03-15 17:09:52 +, Weatherby,Gerard wrote:
> Sum is faster than iteration in the general case.
I'd say this is the special case, not the general case.
> def sum1():
> s = 0
> for i in range(100):
> s += i
> return s
>
> def sum2():
> return sum(range(10
Op 14/03/2023 om 8:48 schreef Alexander Nestorov:
I have the following code:
...
for i in range(151): # 150 iterations
...
Nothing to do with your actual question and it's probably just a small
oversight, but still I thought it was worth a mention: that comment does
not accu
.timeit(sum2, number=100))
---
For Loop Sum: 6.984986504539847
Built-in Sum: 0.5175364706665277
From: Weatherby,Gerard
Date: Wednesday, March 15, 2023 at 1:09 PM
To: python-list@python.org
Subject: Re: Debugging reason for python running unreasonably slow when adding
numbers
Sum is faster t
Wednesday, March 15, 2023 at 11:46 AM
To: python-list@python.org
Subject: RE: Debugging reason for python running unreasonably slow when adding
numbers
*** Attention: This is an external email. Use caution responding, opening
attachments or clicking on links. ***
> Then I'm very confuse
> Then I'm very confused as to how things are being done, so I will shut
> up. There's not enough information here to give performance advice
> without actually being a subject-matter expert already.
Short version: In this specific case "weights" is a 5,147 element list of
floats, and "input" is
On Thu, 16 Mar 2023 at 02:14, Thomas Passin wrote:
>
> On 3/15/2023 11:01 AM, Chris Angelico wrote:
> > On Thu, 16 Mar 2023 at 01:26, David Raymond
> > wrote:
> >> I'm not quite sure why the built-in sum functions are slower than the for
> >> loop,
> >> or why they're slower with the generator
On 3/15/2023 11:01 AM, Chris Angelico wrote:
On Thu, 16 Mar 2023 at 01:26, David Raymond wrote:
I'm not quite sure why the built-in sum functions are slower than the for loop,
or why they're slower with the generator expression than with the list
comprehension.
For small-to-medium data sizes
On 3/15/2023 10:24 AM, David Raymond wrote:
Or use the sum() builtin rather than reduce(), which was
*deliberately* removed from the builtins. The fact that you can get
sum() without importing, but have to go and reach for functools to get
reduce(), is a hint that you probably shouldn't use reduc
On Thu, 16 Mar 2023 at 01:26, David Raymond wrote:
> I'm not quite sure why the built-in sum functions are slower than the for
> loop,
> or why they're slower with the generator expression than with the list
> comprehension.
For small-to-medium data sizes, genexps are slower than list comps,
bu
> Or use the sum() builtin rather than reduce(), which was
> *deliberately* removed from the builtins. The fact that you can get
> sum() without importing, but have to go and reach for functools to get
> reduce(), is a hint that you probably shouldn't use reduce when sum
> will work.
Out of curios
On Tue, 14 Mar 2023 at 16:27, Alexander Nestorov wrote:
>
> I'm working on an NLP and I got bitten by an unreasonably slow behaviour in
> Python while operating with small amounts of numbers.
>
> I have the following code:
>
> ```python
> import random, time
> from functools import reduce
>
> def
On Wed, 15 Mar 2023 at 08:53, Peter J. Holzer wrote:
>
> On 2023-03-14 16:48:24 +0900, Alexander Nestorov wrote:
> > I'm working on an NLP and I got bitten by an unreasonably slow
> > behaviour in Python while operating with small amounts of numbers.
> >
> > I have the following code:
> [...]
> >
On 2023-03-14 16:48:24 +0900, Alexander Nestorov wrote:
> I'm working on an NLP and I got bitten by an unreasonably slow
> behaviour in Python while operating with small amounts of numbers.
>
> I have the following code:
[...]
> # 12x slower than equivalent JS
> sum_ = 0
> for ke
On 3/14/2023 3:48 AM, Alexander Nestorov wrote:
I'm working on an NLP and I got bitten by an unreasonably slow behaviour in
Python while operating with small amounts of numbers.
I have the following code:
```python
import random, time
from functools import reduce
def trainPerceptron(perceptro
18 matches
Mail list logo