On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote:
> Steven D'Aprano writes:
>
>> On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote:
>> > from numpy import dot
>> >
>> > scalar = dot(vec1, vec2)
>>
>> Why would I want to use an already existing library that is fast, well-
>> written and
Steven D'Aprano writes:
> On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote:
>
>> However in this case the procedure by which we derive the value is not
>> important or even interesting. It is much more succinct to think of the
>> operation as a value and express it accordingly. There's
Steven D'Aprano writes:
> On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote:
> > from numpy import dot
> >
> > scalar = dot(vec1, vec2)
>
> Why would I want to use an already existing library that is fast,
> well- written and well-supported, when I can toss together a nasty
> kludge myself?
Steven D'Aprano wrote:
On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote:
Or use the appropriate libraries:
from numpy import dot
scalar = dot(vec1, vec2)
Why would I want to use an already existing library that is fast, well-
written and well-supported, when I can toss together a nasty
On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote:
> Steven D'Aprano wrote:
>> On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote:
>
>>> Adding in the loop construct and name bindings doesn't enhance my
>>> understanding of what a dot-product is. I don't need to see the loop
>>> constr
Steven D'Aprano wrote:
On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote:
Adding in the loop construct and name bindings doesn't enhance my
understanding of what a dot-product is. I don't need to see the loop
construct at all in this case. A dot product is simply the
multiplication of
On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote:
> However in this case the procedure by which we derive the value is not
> important or even interesting. It is much more succinct to think of the
> operation as a value and express it accordingly. There's no need to
> clutter the mind wi
Ben Finney writes:
> J Kenneth King writes:
>
>> Steven D'Aprano writes:
>>
>> > from operator import add
>> > map(add, operandlist1, operandlist2)
>>
>> This is the best solution so far.
>
> Strange to say it's a solution, when it doesn't solve the stated
> problem: to replace use of ‘map()’ w
> Yes, just about any ‘map()’ operation has a corresponding list
> comprehension. (Does anyone know of a counter-example, a ‘map()’
> operation that doesn't have a correspondingly simple list
> comprehension?)
Try turning this into a list comprehension:
vectorsum = lambda *args: map(sum, zip(*a
On Nov 2, 9:01 pm, Ben Finney wrote:
> Anh Hai Trinh writes:
>
> > > Yes, just about any ‘map()’ operation has a corresponding list
> > > comprehension. (Does anyone know of a counter-example, a ‘map()’
> > > operation that doesn't have a correspondingly simple list
> > > comprehension?)
>
> > Tr
On Mon, 02 Nov 2009 20:06:51 -0800, Anh Hai Trinh wrote:
>> Yes, just about any ‘map()’ operation has a corresponding list
>> comprehension. (Does anyone know of a counter-example, a ‘map()’
>> operation that doesn't have a correspondingly simple list
>> comprehension?)
>
> Try turning this into
Anh Hai Trinh writes:
> > Yes, just about any ‘map()’ operation has a corresponding list
> > comprehension. (Does anyone know of a counter-example, a ‘map()’
> > operation that doesn't have a correspondingly simple list
> > comprehension?)
>
> Try turning this into a list comprehension:
>
> vec
Steven D'Aprano writes:
> On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote:
>
> > "Jon P." writes:
> >
> >> I'd like to do:
> >>
> >> resultlist = operandlist1 + operandlist2
> >
> > That's an unfortunate way of expressing it; it's valid Python syntax
> > that doesn't do what you're descri
> Try turning this into a list comprehension:
>
> vectorsum = lambda *args: map(sum, zip(*args))
>
> vectorsum([1,2], [3,4], [5,6])
> ->[9, 12]
> vectorsum([1,2], [3,4], [5,6], [7,8])
> ->[16, 20]
Nvm, it's actually easy:
vectorsum = lambda *args: [sum(i) for i in zip(*args)]
--
http://ma
> On the other hand, list comps using an if clause can't be written as pure
> maps. You can do this:
>
> [func(x) for x in seq if cond(x)]
>
> filter(cond, map(func, seq))
>
> but the second version may use much more temporary memory if seq is huge
> and cond very rarely true.
You could use ifilte
On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote:
> "Jon P." writes:
>
>> I'd like to do:
>>
>> resultlist = operandlist1 + operandlist2
>
> That's an unfortunate way of expressing it; it's valid Python syntax
> that doesn't do what you're describing (in this case, it will bind
> ‘resultlis
On Tue, 03 Nov 2009 09:14:05 +1100, Ben Finney wrote:
> J Kenneth King writes:
>
>> Steven D'Aprano writes:
>>
>> > from operator import add
>> > map(add, operandlist1, operandlist2)
>>
>> This is the best solution so far.
>
> Strange to say it's a solution, when it doesn't solve the stated
>
J Kenneth King writes:
> Steven D'Aprano writes:
>
> > from operator import add
> > map(add, operandlist1, operandlist2)
>
> This is the best solution so far.
Strange to say it's a solution, when it doesn't solve the stated
problem: to replace use of ‘map()’ with a list comprehension.
> I unde
Steven D'Aprano writes:
> On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote:
>
>> I'd like to do:
>>
>> resultlist = operandlist1 + operandlist2
>>
>> where for example
>>
>> operandlist1=[1,2,3,4,5]
>> operandlist2=[5,4,3,2,1]
>>
>> and resultlist will become [6,6,6,6,6]. Using map(), I can
Ben Finney a écrit :
Bruno Desthuilliers writes:
Ben Finney a écrit :
(Does anyone know of a counter-example, a ‘map()’ operation that
doesn't have a correspondingly simple list comprehension?)
... depends on your definition of "simple". There are things I'd
rather not write as a list compre
Bruno Desthuilliers writes:
> Ben Finney a écrit :
> > (Does anyone know of a counter-example, a ‘map()’ operation that
> > doesn't have a correspondingly simple list comprehension?)
>
> ... depends on your definition of "simple". There are things I'd
> rather not write as a list comprehension...
Steven D'Aprano schrieb:
On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote:
I'd like to do:
resultlist = operandlist1 + operandlist2
where for example
operandlist1=[1,2,3,4,5]
operandlist2=[5,4,3,2,1]
and resultlist will become [6,6,6,6,6]. Using map(), I can do:
map(lambda op1,op2: op1 +
Steven D'Aprano REMOVE.THIS.cybersource.com.au> writes:
> >
> > operandlist1=[1,2,3,4,5]
> > operandlist2=[5,4,3,2,1]
> >
> > and resultlist will become [6,6,6,6,6]. Using map(), I can do:
> >
> > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2)
>
> If the two lists are very large,
Ben Finney a écrit :
(snip)
Yes, just about any ‘map()’ operation has a corresponding list
comprehension.
Right AFAICT, but:
(Does anyone know of a counter-example, a ‘map()’
operation that doesn't have a correspondingly simple list
comprehension?)
... depends on your definition of "simple"
"Jon P." writes:
> I'd like to do:
>
> resultlist = operandlist1 + operandlist2
That's an unfortunate way of expressing it; it's valid Python syntax
that doesn't do what you're describing (in this case, it will bind
‘resultlist’ to a new list that is the *concatenation* of the two
original lists
"Jon P." writes:
> I'd like to do:
>
> resultlist = operandlist1 + operandlist2
>
> where for example
>
> operandlist1=[1,2,3,4,5]
> operandlist2=[5,4,3,2,1]
>
> and resultlist will become [6,6,6,6,6]. Using map(), I
> can do:
>
> map(lambda op1,op2: op1 + op2, operandlist1, operandlist2)
>
> Is
On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote:
> I'd like to do:
>
> resultlist = operandlist1 + operandlist2
>
> where for example
>
> operandlist1=[1,2,3,4,5]
> operandlist2=[5,4,3,2,1]
>
> and resultlist will become [6,6,6,6,6]. Using map(), I can do:
>
> map(lambda op1,op2: op1 + op2,
On Mon, Nov 2, 2009 at 12:54 AM, Jon P. wrote:
> I'd like to do:
>
> resultlist = operandlist1 + operandlist2
>
> where for example
>
> operandlist1=[1,2,3,4,5]
> operandlist2=[5,4,3,2,1]
>
> and resultlist will become [6,6,6,6,6]. Using map(), I
> can do:
>
> map(lambda op1,op2: op1 + op2, opera
Hello,
I'll do the following:
[op1+op2 for op1,op2 in zip(operandlist1, operandlist2)]
Best regards,
Javier
2009/11/2 Jon P. :
> I'd like to do:
>
> resultlist = operandlist1 + operandlist2
>
> where for example
>
> operandlist1=[1,2,3,4,5]
> operandlist2=[5,4,3,2,1]
>
> and resultlist will
I'd like to do:
resultlist = operandlist1 + operandlist2
where for example
operandlist1=[1,2,3,4,5]
operandlist2=[5,4,3,2,1]
and resultlist will become [6,6,6,6,6]. Using map(), I
can do:
map(lambda op1,op2: op1 + op2, operandlist1, operandlist2)
Is there any reasonable way to do this via a
30 matches
Mail list logo