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
Steven D'Aprano ste...@remove.this.cybersource.com.au 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
Steven D'Aprano ste...@remove.this.cybersource.com.au 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
On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote:
Steven D'Aprano ste...@remove.this.cybersource.com.au 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,
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,
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 with
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
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
construct at all
Hello,
I'll do the following:
[op1+op2 for op1,op2 in zip(operandlist1, operandlist2)]
Best regards,
Javier
2009/11/2 Jon P. jbpe...@gmail.com:
I'd like to do:
resultlist = operandlist1 + operandlist2
where for example
operandlist1=[1,2,3,4,5]
operandlist2=[5,4,3,2,1]
and
On Mon, Nov 2, 2009 at 12:54 AM, Jon P. jbpe...@gmail.com 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 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,
Jon P. jbpe...@gmail.com 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)
Jon P. jbpe...@gmail.com 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
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.
Steven D'Aprano steven at 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, it
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 +
Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 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
Ben Finney a écrit :
Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 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
Steven D'Aprano ste...@remove.this.cybersource.com.au 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].
J Kenneth King ja...@agentultra.com writes:
Steven D'Aprano ste...@remove.this.cybersource.com.au 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
On Tue, 03 Nov 2009 09:14:05 +1100, Ben Finney wrote:
J Kenneth King ja...@agentultra.com writes:
Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
from operator import add
map(add, operandlist1, operandlist2)
This is the best solution so far.
Strange to say it's a
On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote:
Jon P. jbpe...@gmail.com 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
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 ifilter, imap
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)]
--
Steven D'Aprano st...@remove-this-cybersource.com.au writes:
On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote:
Jon P. jbpe...@gmail.com writes:
I'd like to do:
resultlist = operandlist1 + operandlist2
That's an unfortunate way of expressing it; it's valid Python syntax
Anh Hai Trinh anh.hai.tr...@gmail.com 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
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 a list
On Nov 2, 9:01 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
Anh Hai Trinh anh.hai.tr...@gmail.com 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
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
29 matches
Mail list logo