2016-12-01 18 views
-1

だから私はこのコードを持っている:私は、これらのパラメータと定義された関数を実行するとアレイとマップ出力乗算

# include all functions from the math and numpy library 
from math import * 
from numpy import * 
from functools import reduce 

# definition of the function Sc see Table 2 for details 
def Sc(Dd, ki, ei, Ci, T=298.15, sigma=0.072, gmax=10, g=1+1e-11, inc=1.01): 
    # calculate the A parameter in equation 9 
    A = 8.69251e-6*sigma/T 
    # returns H(xi) as defined in equation 10 
    xi = map(lambda x: x if x < 1 else 1, Ci*(g**3.0 - 1.0)/ei) 
    # xi = Ci*(g**3.0 - 1.0)/ei 
    # calculates the dot product of the hygroscopicity and solub. vectors in Eq. 10 
    k = dot(ki, ei*xi) 
    # defines the function given by equation 9 
    S = lambda D, Dd, k, A: (D**3.0-Dd**3.0)/(D**3.0-Dd**3.0*(1.0-k))*exp(A/D) 
    # implementation of a pairwise max function; f(2,3) returns 3 
    f = lambda x,y: x if x > y else y 
    # returns 1 when g > gmax otherwise return the larger value S(g*Dd) or S(g*Dd*inc) 
    return 1 if g > gmax else reduce(f,[S(g*Dd,Dd,k,A), \ 
Sc(Dd,ki,ei,Ci,T=T,sigma=sigma,gmax=gmax,inc=inc,g=g*inc)]) 

Sc(100e-9, array([0.6,0.2]), array([0.5,0.5]), array([inf,0.1])) 

を、私はこのエラーを取得しています:

k = dot(ki, ei*xi) 
TypeError: unsupported operand type(s) for *: 'float' and 'map' 

私はそれが自明だと知っていますが、それを避ける方法は?実行する方法はありますか?

k = dot(ki, ei*xi) 

エラーはありませんか?

ありがとうございました!

+0

'map'はすぐには実行されません。 'array(list(map(lambda x:x x <1 else 1、Ci *(g ** 3.0 - 1.0)/ ei)))' – Goodies

+0

ありがとう! :)それはすべきであるとして動作します。 – Jakub

答えて

1

あなたは、例えばPythonの3 で明示的にmapの結果を評価する必要があります:

xi = np.array(map(lambda x: x if x < 1 else 1, Ci*(g**3.0 - 1.0)/ei))