a = [范围(4)中n的[λt:t ** n]] [英] a=[ lambda t: t**n for n in range(4) ]
问题描述
我正在考虑以下内容;
I was thinking about something like the following;
a = [t ** n for n in范围(4)]
回溯(最近一次调用最后一次):
文件"< stdin>",第1行,在?
NameError:名称''t''未定义
或
a = [lambda t:t ** n n为范围(4)]
t = 2
a
[< function< lambda>在0x403dcc6c>,< function< lambda>在0x403dcca4>,
< function< lambda>在0x403dccdc>,< function< lambda>在0x403dcd14>] t = 3
a
[< function< lambda>在0x403dcc6c>,< function< lambda>在0x403dcca4>,
< function< lambda>在0x403dccdc>,< function< lambda>在0x403dcd14>]
a=[ t**n for n in range(4) ] Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name ''t'' is not defined
or
a=[ lambda t: t**n for n in range(4) ]
t=2
a [<function <lambda> at 0x403dcc6c>, <function <lambda> at 0x403dcca4>,
<function <lambda> at 0x403dccdc>, <function <lambda> at 0x403dcd14>] t=3
a [<function <lambda> at 0x403dcc6c>, <function <lambda> at 0x403dcca4>,
<function <lambda> at 0x403dccdc>, <function <lambda> at 0x403dcd14>]
有可能吗?你能给我一些建议吗?
is something like that possible? Will you give me advice about that?
推荐答案
我************* @ gmail.com 写道:
我在考虑以下内容;
I was thinking about something like the following;
a = [t ** n for n in range(4)]
Traceback(最近一次调用最后一次) ):
文件"< stdin>",第1行,在?
NameError:名称''t''未定义
或
< br => a = [lambda t:t ** n为范围内的n(4)]
t = 2
a
也许你的意思是:a = lambda t:[t ** n代表范围内的n(4)]
a(2)
[1,2,4,8]
但是写得更好:def a(t):
...返回[t ** n代表范围内的n(4)]
...
a (2)
[1,2,4,8]
a=[ t**n for n in range(4) ]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name ''t'' is not defined
or
a=[ lambda t: t**n for n in range(4) ]
t=2
a
Perhaps you mean: a = lambda t: [t**n for n in range(4)]
a(2) [1, 2, 4, 8]
but that is better written as: def a(t): ... return [t**n for n in range(4)]
...
a(2) [1, 2, 4, 8]
Michael
Michael
请发布你的tr的描述ying to
完成而不是要求我们采取你可能的
解决方案并试图找出问题所在。
你可以这样做:
def foo(t,r):
返回[t ** n表示范围内的r(r)]
a = foo(2,4)
a
[1,2,4,8]
a = foo(3,6)
a
[1,3,9,27,82,243]
但我真的不知道你想要什么。
拉里
我************* @ gmail.com 写道:
Please post a description of what you are trying to
accomplish instead of asking us to take your possible
solution and try to figure out what the problem was.
You can do:
def foo(t, r):
return [t**n for n in range(r)]
a=foo(2, 4)
a
[1, 2, 4, 8]
a=foo(3,6)
a
[1, 3, 9, 27, 81, 243]
but I don''t really know what you want.
Larry
me*************@gmail.com wrote:
我正在考虑以下内容;
I was thinking about something like the following;
a = [t ** n for n in range(4)]
Traceback(最近一次呼叫最后一次):
文件"< stdin>",第1行,在?
NameError:名称''t''未定义
或
a = [lambda t:t ** n,n为范围(4)]
t = 2
a
[< function< lambda >在0x403dcc6c>,< function< lambda>在0x403dcca4>,
< function< lambda>在0x403dccdc>,< function< lambda>在0x403dcd14>]
t = 3
a
a=[ t**n for n in range(4) ]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name ''t'' is not defined
or
a=[ lambda t: t**n for n in range(4) ]
t=2
a
[<function <lambda> at 0x403dcc6c>, <function <lambda> at 0x403dcca4>,
<function <lambda> at 0x403dccdc>, <function <lambda> at 0x403dcd14>]
t=3
a
[< function< lambda>在0x403dcc6c>,< function< lambda>在0x403dcca4>,
< function< lambda>在0x403dccdc>,< function< lambda>在0x403dcd14>]
有可能吗?你能给我一些建议吗?
[<function <lambda> at 0x403dcc6c>, <function <lambda> at 0x403dcca4>,
<function <lambda> at 0x403dccdc>, <function <lambda> at 0x403dcd14>]
is something like that possible? Will you give me advice about that?
Thanx你的回复。
我正在寻找函数数组。
类似a = [sin(x),cos(x)]
Thanx for your replies.
I''m looking for array of functions.
Something like a=[ sin(x) , cos(x) ]
x = 0.0
a
[0,1] x = 1.0
a
....
当然它可以通过def cratearray(x)制作:
x=0.0
a [0, 1] x=1.0
a ....
of course it can be made by def cratearray(x):
.... ~~~~
。 ...返回
a = createarray(1.0)
但这不是我要求的。自动化的东西。
.... ~~~~
.... return a
a=createarray(1.0)
but this isn''t what i am asking for. something automized.
这篇关于a = [范围(4)中n的[λt:t ** n]]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!