TypeError:元组索引必须是整数或切片,而不是str scipy.optimize

时间:2018-07-20 21:39:17

标签: python optimization scipy typeerror minimize

我尝试使用scipy.optimize.minimize。这是我的代码:

def rry_fit(gamma, *args):
    data = args['data']
    data.time.shiftted = data.time - gamma 
    rsqr = rry.rry_cal(data)
    return(rsqr)

   minimize(rry_fit, gamma0, args={'data': df}, method='nelder-mead', options={'xtol': 1e-8, 'disp': True})

但是,在data = args ['data']行中出现以下错误。

TypeError: tuple indices must be integers or slices, not str

谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

public void ProcessRequest(HttpContext context) { if (context.Request.Files.Count > 0) { HttpFileCollection files = context.Request.Files; string name = context.Request.Form["name"]; string email = context.Request.Form["email"]; string msg = context.Request.Form["msg"]; for (int i = 0; i < files.Count; i++) { HttpPostedFile file = files[i]; string fname; //string fname = context.Request.Form["str"].ToString(); if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = file.FileName; } fname = Path.Combine(context.Server.MapPath("~/images/"), fname); MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("name@gmail.com"); mail.To.Add("name@gmail.com"); mail.Subject = "new order"; mail.Body =msg; mail.Attachments.Add(new Attachment(file.InputStream,file.FileName)); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("name@gmail.com","password"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } } } 是一个元组,而不是字典。将其从args更改为*args或将**kwargs更改为args [0],其中0是数据所在的数字。