【发布时间】:2018-02-15 15:23:53
【问题描述】:
我想将参数元组 args (元组的长度因其他一些函数而变化)传递给一个函数,该函数有效
def myf(x1,x2,x3,....)
return something involving x1,x2....
args = (y1,y2,.....)
call myf with args as myf(y1,y2,....)
您是如何做到这一点的?在我的实际问题中,我正在使用sympy 函数myf 实际上是reshape 而变量参数列表args 是通过获取一些n-d 数组的形状生成的元组,比如A,所以args = A.shape。最后我想根据A的形状重塑另一个数组B。一个最简单的例子
from sympy import *
A = Array(symbols('a:2:3:4:2'),(2,3,4,2))
B = Array(symbols('b:8:3:2'),(8,3,2))
args = A.shape
print args
print B.reshape(2,3,4,2) # reshape(2,3,4,2) is the correct way to call it
print B.reshape(args) # This is naturally wrong since reshape((2,3,4,2)) is not the correct way to call reshape
【问题讨论】:
标签: python python-2.7 functional-programming python-2.x