Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'parameters': 0.04; '"""': 0.07; '(all': 0.07; 'skip:p 60': 0.07; 'variables': 0.07; 'file)': 0.09; 'obj': 0.09; 'parameter': 0.09; 'params': 0.09; 'repeated': 0.09; 'skip:_ 80': 0.09; 'def': 0.12; 'received:141': 0.14; '"""print': 0.16; '"""read': 0.16; '0.2': 0.16; '917': 0.16; ':::': 0.16; 'affiliates,': 0.16; 'bounds': 0.16; 'coeff': 0.16; 'cons': 0.16; 'distinct': 0.16; 'func': 0.16; 'hardcoded': 0.16; 'issue?': 0.16; 'lambda': 0.16; 'numpy': 0.16; 'operands': 0.16; 'prep': 0.16; 'received:mgd.msft.net': 0.16; 'received:msft.net': 0.16; 'res': 0.16; 'subject:Problems': 0.16; 'variables,': 0.16; 'x1,': 0.16; 'subject:python': 0.16; 'thanks,': 0.17; 'all,': 0.19; '<': 0.19; 'file,': 0.19; 'written': 0.21; 'help.': 0.21; 'input': 0.22; 'import': 0.22; 'print': 0.22; 'error': 0.23; 'entries': 0.24; 'specify': 0.24; 'initial': 0.24; 'designated': 0.26; 'purposes': 0.26; 'second': 0.26; 'values': 0.27; 'function': 0.29; 'correct': 0.29; 'skip:p 30': 0.29; 'scanned': 0.29; 'specified': 0.30; 'skip:( 20': 0.30; 'gives': 0.31; 'code': 0.31; 'getting': 0.31; '1.3': 0.31; 'file': 0.32; 'this.': 0.32; '(including': 0.33; 'running': 0.33; 'header:Received:9': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'problem': 0.35; 'but': 0.35; 'there': 0.35; 'url:rec-html40': 0.35; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'should': 0.36; 'url:microsoft': 0.37; 'received:10': 0.37; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'law,': 0.38; 'url:office': 0.38; 'to:addr :python-list': 0.38; 'files': 0.38; 'skip:- 10': 0.38; 'url:schemas': 0.38; 'url:omml': 0.39; 'url:2004': 0.39; 'skip:_ 30': 0.39; 'skip:& 20': 0.39; 'delete': 0.39; 'url:12': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'days': 0.60; 'from:no real name:2**0': 0.61; 'lower': 0.61; 'skip:o 30': 0.61; 'numbers': 0.61; 'information': 0.63; 'our': 0.64; 'sum': 0.64; 'more': 0.64; 'total': 0.65; 'taking': 0.65; 'investment': 0.66; 'broadcast': 0.68; 'messaging': 0.68; 'policy.': 0.68; 'upper': 0.74; 'power': 0.76; '0.8': 0.84; 'different.': 0.84; 'investments': 0.91; 'proprietary,': 0.91; 'vars': 0.91; 'instant': 0.97 From: To: Subject: Problems in python pandas Thread-Topic: Problems in python pandas Thread-Index: Ac/R2Q82PkGuBWlsQiyMOy5TBIPviA== Date: Tue, 16 Sep 2014 18:08:39 +0000 Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [141.251.107.196] Content-Type: multipart/alternative; boundary="_000_c46041c090ae4e91b22be0444562e451DM2PR42MB061048dmgdmsft_" MIME-Version: 1.0 X-OrganizationHeadersPreserved: AMRXH4002.dir.svc.accenture.com X-CrossPremisesHeadersFiltered: AMRXE4001.dir.svc.accenture.com X-OrganizationHeadersPreserved: AMRXE4001.dir.svc.accenture.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:170.252.43.203; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(438002)(3029003); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR08MB705; H:AMRXE4001.dir.svc.accenture.com; FPR:; MLV:ovrnspm; PTR:fope.amr.smtp.accenture.com,amrxe4141.accenture.com; MX:1; A:1; LANG:en; X-CrossPremisesHeadersPromoted: BN1AFFO11FD015.protection.gbl X-CrossPremisesHeadersFiltered: BN1AFFO11FD015.protection.gbl X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:; X-Forefront-PRVS: 03361FCC43 Received-SPF: Pass (protection.outlook.com: domain of accenture.com designates 170.252.43.203 as permitted sender) receiver=protection.outlook.com; client-ip=170.252.43.203; helo=AMRXE4001.dir.svc.accenture.com; Authentication-Results: spf=pass (sender IP is 170.252.43.203) smtp.mailfrom=prashant.mudgal@accenture.com; X-OriginatorOrg: accenture.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 489 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410900289 news.xs4all.nl 2842 [2001:888:2000:d::a6]:56804 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77945 --_000_c46041c090ae4e91b22be0444562e451DM2PR42MB061048dmgdmsft_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi All, I am having some problem in python. I have written the code import pandas as pd import numpy as np from scipy.optimize import minimize pd.set_option('display.mpl_style', 'default') """Read the input file into the dataframe""" """T1 file contains the decisi= on variables, corresponding investments and their upper and lower bounds""" df =3D pd.DataFrame.from_csv('C:\Users\prashant.mudgal\Downloads\T1.csv') """T2 file contains the parameters for the decision variables, note that th= ere can be 2 or more entries for the same decison variable""" """ Our objec= tive func will be prep from T2 file , it will be of the form sum (all DV in= params file) (a*(b + c * DV_name)** power) """ df2 =3D pd.DataFrame.from_csv('C:\Users\prashant.mudgal\Downloads\T2.csv') """subset of DV""" decisionVars=3D df2['DV'] """subset for coeff """ coeff =3D df2['coef'] """subset for power""" power =3D df2['p'] x0 =3D df['Hist_Inv'] bnds =3D df[['LB','UB']].values def objFunc(decisionVars,sign=3D1.0) : return sign*(sum(coeff.values[0:] *(df2['weight_f'].values[0:] + df2['weigh= t_v'].values[0:] * decisionVars[0:])**power.values[0:])) """bounds for the decision variables have been hardcoded """ """ The bounds= have been hardcoded and it will be cumbersome if there are thousands of De= cision vars """ """ The bounds have been specified in T1.csv file, we want = to ream them via the file """ """ Though we are not using constraints as of now, but is it correct form""= " """ How to form the constraints for say x + y < 5 ? """ cons =3D ({'type'= : 'ineq', 'fun': lambda x: decisionVars[1] - 2 * decisionVars[1] + 2}, {'ty= pe': 'ineq', 'fun': lambda x: -decisionVars[2] - 2 * decisionVars[1] + 6}, = {'type': 'ineq', 'fun': lambda x: -decisionVars[0] + 2 * decisionVars[1] + = 2}) """ the second parameter is the initial values that needs to be optimized""= " """ Now, the number of distinct decision vars in the files are 3 in numbe= rs while the total number of decision vars are 12 in number . if we specify= x0 as the dataframe of investment (3 in number in the T1 file) , then it g= ives error that ::: operands could not be broadcast together with shapes (1= 2,) (3,)""" res =3D minimize(objFunc, x0,args=3D(-1.0,),method=3D'SLSQP',bounds =3D bnd= s, options=3D{'disp': True}) """Print the results""" print (res) T1.csv is like DV LB UB Hist_Inv X1 0.7 1.3 28462739.43 X2 0.7 1.3 177407.1= 8 X3 0.7 1.3 1423271.12 T2.csv is Count DV weight_f weight_v p coef 1 X1 2.310281831 3.661156016 0.5 1828.105881 2 X1 0.693084549 2.20503016 0.5 1460.686147 3 X1 0.207925365 2.030522789 0.5 1436.277144 4 X1 0 5.248353307 0.8 1050.493355 5 X1 0 1.591805116 0.8 983.9964128 6 X1 0 1.933056056 0.8 459.9371809 7 X2 7.322516444 138 0.5 387.4659072 8 X2 3.661258222 139 0.5 606.8684771 9 X2 1.830629111 176.5 0.5 358.8902965 10 X3 164294.4758 77024 0.2 282.0477107 11 X3 98576.68545 122261.4 0.2 345.9217482 12 X3 59146.01127 166242.84 0.2 364.9587162 I create my obj function using vars in T2, there are a lot of vars which ar= e repeated in T2.csv on running optimization I am getting the error operand= s could not be broadcast together with shapes (12,) (3,) because it is taki= ng all the variables in T2 as different. How should I avoid this issue? X1,= X2 AND X3 are the only three vars here. Please help. I am stuck for past many days on this. Thanks, Prashant Mudgal AI (Accenture Interactive) +1 917 615 3574(Cell) ________________________________ This message is for the designated recipient only and may contain privilege= d, proprietary, or otherwise confidential information. If you have received= it in error, please notify the sender immediately and delete the original.= Any other use of the e-mail by you is prohibited. Where allowed by local l= aw, electronic communications with Accenture and its affiliates, including = e-mail and instant messaging (including content), may be scanned by our sys= tems for the purposes of information security and assessment of internal co= mpliance with Accenture policy. ___________________________________________________________________________= ___________ www.accenture.com --_000_c46041c090ae4e91b22be0444562e451DM2PR42MB061048dmgdmsft_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi All,

 

I am having some problem in python.

 

I have written the code

import pandas as pd=

import numpy as np<= /o:p>

from scipy.optimize impo= rt minimize

pd.set_option('display.m= pl_style', 'default')

"""Read the input file into the dataf= rame""" """T1 file contains the decision vari= ables, corresponding investments and their upper and lower bounds"&quo= t;"

df =3D pd.DataFrame.from= _csv('C:\Users\prashant.mudgal\Downloads\T1.csv')

"""T2 file contains the parameters fo= r the decision variables, note that there can be 2 or more entries for the = same decison variable""" """ Our objective fu= nc will be prep from T2 file , it will be of the form sum (all DV in params file) (a*(b + c * = DV_name)** power) """

df2 =3D pd.DataFrame.fro= m_csv('C:\Users\prashant.mudgal\Downloads\T2.csv')

"""subset of DV"""

decisionVars=3D df2['DV'= ]

"""subset for coeff """= ;

coeff =3D df2['coef']

"""subset for power"""=

power =3D df2['p']<= /o:p>

 =

x0 =3D df['Hist_Inv']

 =

bnds =3D df[['LB','UB']]= .values

 =

 =

 =

 =

def objFunc(decisionVars= ,sign=3D1.0) :

return sign*(sum(coeff.v= alues[0:] *(df2['weight_f'].values[0:] + df2['weight_v'].values[0:] * d= ecisionVars[0:])**power.values[0:]))

"""bounds for the decision variables = have been hardcoded """ """ The bounds have b= een hardcoded and it will be cumbersome if there are thousands of Decision = vars """ """ The bounds have been specified in T1.csv file, we want to ream them via the file &quo= t;""

""" Though we are not using constrain= ts as of now, but is it correct form""" """ H= ow to form the constraints for say x + y < 5 ? """ co= ns =3D ({'type': 'ineq', 'fun': lambda x: decisionVars[1] - 2 * decisionVars[1] + 2}, {'type': 'ineq', 'fun': lambda x: -decisio= nVars[2] - 2 * decisionVars[1] + 6}, {'type': 'ineq', 'fun': lambda x: = -decisionVars[0] + 2 * decisionVars[1] + 2})

""" the second parameter is the initi= al values that needs to be optimized""" """ N= ow, the number of distinct decision vars in the files are 3 in numbers whil= e the total number of decision vars are 12 in number . if we specify x0 as the dataframe of investment (3= in number in the T1 file) , then it gives error that ::: operands could no= t be broadcast together with shapes (12,) (3,)"""=

res =3D minimize(objFunc= , x0,args=3D(-1.0,),method=3D'SLSQP',bounds =3D bnds,

    =        options=3D{'disp': True})

"""Print the results"""= ;

print (res)

T1.csv is like DV LB UB Hist_Inv X1 0.7 1.3 28462739= .43 X2 0.7 1.3 177407.18 X3 0.7 1.3 1423271.12

T2.csv is

Count   DV&nbs= p; weight_f    weight_v    p   coef=

1   X1  2= .310281831 3.661156016 0.5 1828.105881

2   X1  0= .693084549 2.20503016  0.5 1460.686147

3   X1  0= .207925365 2.030522789 0.5 1436.277144

4   X1  0=    5.248353307 0.8 1050.493355

5   X1  0=    1.591805116 0.8 983.9964128

6   X1  0=    1.933056056 0.8 459.9371809

7   X2  7= .322516444 138 0.5 387.4659072

8   X2  3= .661258222 139 0.5 606.8684771

9   X2  1= .830629111 176.5   0.5 358.8902965

10  X3  164294= .4758 77024   0.2 282.0477107

11  X3  98576.= 68545 122261.4    0.2 345.9217482

12  X3  59146.= 01127 166242.84   0.2 364.9587162

I create my obj function using vars in T2, there are= a lot of vars which are repeated in T2.csv on running optimization I am ge= tting the error operands could not be broadcast together with shapes (12,) (3,) because it is taking all the variables in T2 as dif= ferent. How should I avoid this issue? X1, X2 AND X3 are the only three var= s here.

Please help. I am stuck for past many days on this.<= o:p>

 

Thanks,

Prashant = Mudgal

&= nbsp;

AI (Ac= centure Interactive)

+1=   917 615 3574(Cell)

 




This message is for the designated recipient only and may contain privilege= d, proprietary, or otherwise confidential information. If you have received= it in error, please notify the sender immediately and delete the original.= Any other use of the e-mail by you is prohibited. Where allowed by local law, electronic communications w= ith Accenture and its affiliates, including e-mail and instant messaging (i= ncluding content), may be scanned by our systems for the purposes of inform= ation security and assessment of internal compliance with Accenture policy.
___________________________________________________________________________= ___________

www.accenture.com
--_000_c46041c090ae4e91b22be0444562e451DM2PR42MB061048dmgdmsft_--