给定二维列表和值库的所有值的加权平均值

时间:2018-10-29 16:24:52

标签: python python-3.x list loops

我有三个不同的列表:

a = [[7,5,8],[3,4]]

value = [9, 5, 7, 8, 3, 4, 10]
weight = [100.0, 65.0, 25.0, 25.0, 100.0, 65.0, 25.0]
capacity = [1000.0, 15.0, 700.0, 700.0, 1000.0, 15.0, 700.0]

我正在尝试查找a的给定条目中所有值之和的权重和容量,例如在a [0]中:

weight_a[0] = (700*25 + 15*65 + 700*25) / (700 + 15 + 700)
capacity_a[0] = 700 + 15 + 700

weight_a[1] = (1000*100 + 15*65) / (1000 + 15)
capacity_a[1] = 1000 + 15

因此weight_a和Capacity_a是a的每个列表中条目的weighted_平均值和容量之和。

值7的权重为25,容量为700:

7 is value[2] so capacity[2] = 700 and weight[2] = 25

weight_a方程是总和(价值权重*价值能力)/所有价值能力的总和

capacity_a方程是所有值的容量之和

我一直在努力提出问题,似乎无法解决。我正在尝试压缩(值,容量,重量),但在给定2d列表a的情况下,我不确定如何访问。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以将@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { private static final String[] ALLOWED_GET_URLS = { "/", //"/about", "/login/**", "/frontend/**", "/VAADIN/**", "/favicon.ico" }; private static final String[] ALLOWED_POST_URLS = { "/" }; //@formatter:off @Override protected void configure(HttpSecurity http) throws Exception { http .csrf() .disable() .authorizeRequests() .mvcMatchers(HttpMethod.GET, ALLOWED_GET_URLS) .permitAll() .mvcMatchers(HttpMethod.POST, ALLOWED_POST_URLS) .permitAll() .anyRequest() .fullyAuthenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout() .logoutSuccessUrl("/") .permitAll(); } //@formatter:on } 与自定义功能一起使用,然后使用map对结果进行解压缩:

zip