michel paul <mpaul...@gmail.com> wrote:

You could use *n for your parameter. It allows you to enter an arbitrary number 
of arguments:

def a(*n): return [1/k^2 for k in n]


a(2,4,6) ---> [1/4,1/16,1/36]


a(5) ---> [1/25]


Not exactly what you were wanting, but pretty close.

But - why not just go ahead and define a(n) for the nth term and then use map 
or list comprehension to expand the sequence? It seems to me that's a lot 
clearer.



On Wed, Nov 2, 2011 at 12:04 PM, A. Jorge Garcia <calcp...@aol.com> wrote:


Sorry, what I meant to say was: what if I define a function such as
def a(n):
return 1/n**2
so running
a([2,4,6])
yields
[1/4,1/16,1/36]
Thanx,
A. Jorge Garcia
Applied Math and CompSci


-- 

==================================
"What I cannot create, I do not understand."


- Richard Feynman

==================================
"Computer science is the new mathematics."


- Dr. Christos Papadimitriou
==================================


-- 
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To post to this group, send email to sage-edu@googlegroups.com.
To unsubscribe from this group, send email to 
sage-edu+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sage-edu?hl=en.


Well!, I guess I'm still used to MATLAB or Octave where a function can process 
an entire matrix whether it be 1x1, 1xn, nx1, nxn or nxm.

How about this, whether you use map() or a list comprehension, can I use 
@cython or @parallel or both to improve runtime when processing a huge list?
Thanx,
A. Jorge Garcia
Applied Math and CompSci
http://shadowfaxrant.blogspot.com
http://www.youtube.com/calcpage2009
Sent via DROID on Verizon Wireless

-- 
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To post to this group, send email to sage-edu@googlegroups.com.
To unsubscribe from this group, send email to 
sage-edu+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sage-edu?hl=en.

Reply via email to