微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从方法中获取赋值?

如何解决如何从方法中获取赋值?

我想在设置某个字段的类中收集方法,例如 import numpy as np import itertools from collections import Counter import pandas as pd bag = np.hstack(( np.repeat(0,80),np.repeat(1,21),np.repeat(3,5),np.repeat(7,1) )) #107*106*105*104*103*102*101*100*99*98 #Out[176]: 127506499163211168000 #Permutations ##Need to reduce the number to sample from without changing the number of possible combinations reduced_bag = np.hstack(( np.repeat(0,10),## 0 can be chosen all 10 times np.repeat(1,## 1 can be chosen all 10 times np.repeat(3,## 3 can be chosen up to 5 times np.repeat(7,1) ## 7 can be chosen once )) ## There are 96 unique combinations number_unique_combinations = len(set(list(itertools.combinations(reduced_bag,10)))) ### sorted list of all combinations unique_combinations = sorted(list(set(list(itertools.combinations(reduced_bag,10))))) ### sum of each unique combination sums_list = [sum(uc) for uc in unique_combinations] ### probability for each unique combination probability_dict = {0:80,1:21,3:5,7:1} ##Dictionary to refer to n = 107 ##Number in the bag probability_list = [] ##This part is VERY slow to run because of the itertools.permutations for x in unique_combinations: print(x) p = 1 ##Start with the probability again n = 107 ##Start with a full bag for each combination count_x = Counter(x) for i in x: i_left = probability_dict[i] - (Counter(x)[i] - count_x[i]) ##Number of that type left in bag p *= i_left/n ##Multiply the probability n = n-1 # non replacement count_x[i] = count_x[i] - 1 ##Reduce the number in the bag p *= len(set(list(itertools.permutations(x,10)))) ##Multiply by the number of permutations per combination probability_list.append(p) ##sum(probability_list) ## Has a rounding error ##Out[57]: 1.0000000000000002 ## ##Put the combinations into dataframe ar = np.array((unique_combinations,sums_list,probability_list)) df = pd.DataFrame(ar).T ##Name the columns df.columns = ["combination","sum","probability"] ## probability that sum is >= 6 df[df["sum"] >= 6]['probability'].sum() ## 0.24139909236232826 ## probability that sum is == 6 df[df["sum"] == 6]['probability'].sum() ## 0.06756408790812335 。 我知道如何获取方法int i = 2;

Statement

assignments 似乎是表达式,我不知道如何找到它们。如何在方法获取(赋值)表达式?

解决方法

if (statemet.isExpressionStmt()) {
    Expression e = statement.asExpressionStmt().getExpression();

成功了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。