En Thu, 19 Mar 2009 08:06:35 -0200, mattia escribió:
OK, understood. Now, as a general rule, is it correct to say:
- use generator expression when I just need to iterate over the list or
call a function that involve an iterator (e.g. sum) and get the result,
so the list is not necessary anymore
Il Wed, 18 Mar 2009 23:31:09 -0200, Gabriel Genellina ha scritto:
> En Wed, 18 Mar 2009 18:49:19 -0200, mattia escribió:
>> Il Wed, 18 Mar 2009 13:20:14 -0700, Aahz ha scritto:
>>> In article <49c1562a$0$1115$4fafb...@reader1.news.tin.it>, mattia
>>> wrote:
Yeah, and I believe that we
En Wed, 18 Mar 2009 18:49:19 -0200, mattia escribió:
Il Wed, 18 Mar 2009 13:20:14 -0700, Aahz ha scritto:
In article <49c1562a$0$1115$4fafb...@reader1.news.tin.it>, mattia
wrote:
Yeah, and I believe that we can say the same for: 1 - t = [x*2 for x in
range(10)]
2 - t = list(x*2 for x in rang
Il Wed, 18 Mar 2009 13:20:14 -0700, Aahz ha scritto:
> In article <49c1562a$0$1115$4fafb...@reader1.news.tin.it>, mattia
> wrote:
>>
>>Yeah, and I believe that we can say the same for: 1 - t = [x*2 for x in
>>range(10)]
>>2 - t = list(x*2 for x in range(10))
>>or not?
>
> The latter requires ge
In article <49c1562a$0$1115$4fafb...@reader1.news.tin.it>,
mattia wrote:
>
>Yeah, and I believe that we can say the same for:
>1 - t = [x*2 for x in range(10)]
>2 - t = list(x*2 for x in range(10))
>or not?
The latter requires generator expressions, which means it only works with
Python 2.4 or h
Il Wed, 18 Mar 2009 09:34:57 -0700, Aahz ha scritto:
> In article , Peter Otten
> <__pete...@web.de> wrote:
>>mattia wrote:
>>>
>>> cpop += [nchromosome1] + [nchromosome2]
>>
>>I'd write that as
>>
>>cpop.append(nchromosome1)
>>cpop.append(nchromosome2)
>>
>>thus avoiding the intermediate
In article ,
Peter Otten <__pete...@web.de> wrote:
>mattia wrote:
>>
>> cpop += [nchromosome1] + [nchromosome2]
>
>I'd write that as
>
>cpop.append(nchromosome1)
>cpop.append(nchromosome2)
>
>thus avoiding the intermediate lists.
You could also write it as
cpop += [nchromosome1, nchromo
On 05 Mar 2009 20:43:41 GMT, mattia wrote:
>> for a, b in zip(*[iter(pop)]*2):
> In the python documentation there is a similar example, well, the obscure
> thing here is the usage of *[iter(pop)]! Then I believe that I can safely
> say that you iterate over the values 0 and 1, 2 and 3 etc.
Il Thu, 05 Mar 2009 18:07:29 +0100, Peter Otten ha scritto:
> mattia wrote:
>
>> The last question: how can I improve readability in this piece of code?
>>
>> def crossover(pop, prob=0.6):
>> """
>> With a crossover probability cross over the parents to form new
>> offspring. If no c
> for a, b in zip(*[iter(pop)]*2):
In the python documentation there is a similar example, well, the obscure
thing here is the usage of *[iter(pop)]! Then I believe that I can safely
say that you iterate over the values 0 and 1, 2 and 3 etc. because the
zip automatically updates the index, i
ssical genetic algorithm example: given a
>>> population of chromosomes, encoded using 1 and 0, find the chromosome
>>> with the maximum number of 1s. Now, despite all the code used to
>>> implement the solution, I'm wondering if there is a better way to use
>>> the s
On Thu, 05 Mar 2009 18:07:29 +0100, Peter Otten <__pete...@web.de> wrote:
[snip]
>
> Just for fun here's an alternative version of your function
>
> def generate_crossover(pop, prob):
> for a, b in zip(*[iter(pop)]*2):
. . .
Good grief! That's devilishly obscure.
--
To email me, substitute
mattia wrote:
... The last question: how can I improve readability in this piece of code?
def crossover(pop, prob=0.6):
"""
With a crossover probability cross over the parents to form new
offspring. If no crossover was performed, offspring is the exact copy of
parents.
"""
c
mattia wrote:
> The last question: how can I improve readability in this piece of code?
>
> def crossover(pop, prob=0.6):
> """
> With a crossover probability cross over the parents to form new
> offspring. If no crossover was performed, offspring is the exact copy
> of parents. "
1 and 0, find the chromosome
>> with the maximum number of 1s. Now, despite all the code used to
>> implement the solution, I'm wondering if there is a better way to use
>> the so-called roulette wheel selection in this problem. Here I paste
>> the code of my solution, a
Il Thu, 05 Mar 2009 12:54:39 +0100, Peter Otten ha scritto:
> mattia wrote:
>
>> Il Thu, 05 Mar 2009 10:46:58 +0100, Peter Otten ha scritto:
>>
>>> mattia wrote:
>>>
> Note how get_roulette_wheel() is now completeley independent of the
> concrete problem you are using it for.
mattia wrote:
> Il Thu, 05 Mar 2009 10:46:58 +0100, Peter Otten ha scritto:
>
>> mattia wrote:
>>
Note how get_roulette_wheel() is now completeley independent of the
concrete problem you are using it for.
>>>
>>> Ok, but also a lot more memory consuming ;-)
>>
>> I don't think so. Py
Il Thu, 05 Mar 2009 10:46:58 +0100, Peter Otten ha scritto:
> mattia wrote:
>
>>> Note how get_roulette_wheel() is now completeley independent of the
>>> concrete problem you are using it for.
>>
>> Ok, but also a lot more memory consuming ;-)
>
> I don't think so. Python references objects; th
mattia wrote:
>> Note how get_roulette_wheel() is now completeley independent of the
>> concrete problem you are using it for.
>
> Ok, but also a lot more memory consuming ;-)
I don't think so. Python references objects; therefore the list
[tiny_little_thing]*N
does not consume more memory th
> Note how get_roulette_wheel() is now completeley independent of the
> concrete problem you are using it for.
Ok, but also a lot more memory consuming ;-)
--
http://mail.python.org/mailman/listinfo/python-list
1 and 0, find the chromosome
>> with the maximum number of 1s. Now, despite all the code used to
>> implement the solution, I'm wondering if there is a better way to use
>> the so-called roulette wheel selection in this problem. Here I paste
>> the code of my solution, a
the code used to implement the
> solution, I'm wondering if there is a better way to use the so-called
> roulette wheel selection in this problem. Here I paste the code of my
> solution, any advice will be helpful:
Your code looks good to me.
> from random import randint, random
&
On Wed, 2009-03-04 at 18:02 +, mattia wrote:
> ri = randint(0, len(rw) - 1)
> print("Random index:", rw[ri], ", value:", pop[rw[ri]])
you probably want random.choice(rw)
--
http://mail.python.org/mailman/listinfo/python-list
ution, I'm wondering if there is a better way to use the so-called
roulette wheel selection in this problem. Here I paste the code of my
solution, any advice will be helpful:
from random import randint, random
def create_chromosome(min, max, length):
chromosome = []
for i in ra
24 matches
Mail list logo