删除满足某些条件的子阵列的问题

时间:2019-06-21 12:24:37

标签: python numpy

我试图生成一个数组数组,然后删除所有满足某些条件的子数组。但是,我的代码似乎没有这样做,而且我不确定为什么。

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

e = np.arange(.01,1,.01)
h1 = np.arange(.01,1,.01)
h2 = np.arange(.01,1,.01)
e_given_d = np.arange(.01,1,.01)
e_h1_h2 = np.array(np.meshgrid(e,h1,h2)).T.reshape(-1,3)
e_h1_ed = np.array(np.meshgrid(e,h1,e_given_d)).T.reshape(-1,3)
e_h2_ed = np.array(np.meshgrid(e,h2,e_given_d)).T.reshape(-1,3)
h1_h2_ed = np.array(np.meshgrid(h1,h2,e_given_d)).T.reshape(-1,3)
e = np.concatenate((e_h1_h2[:,0],e_h2_ed[:,0],e_h1_ed[:,0]),axis=1).reshape(-1,1)
h1 = np.concatenate((e_h1_h2[:,1],e_h1_ed[:,1],h1_h2_ed[:,0]),axis=1).reshape(-1,1)
h2 = np.concatenate((e_h1_h2[:,2],e_h2_ed[:,1],h1_h2_ed[:,1]),axis=1).reshape(-1,1)
e_given_d = np.concatenate((e_h1_ed[:,2],e_h2_ed[:,2],h1_h2_ed[:,2]),axis=1).reshape(-1,1)
all_combos = np.hstack((e,h1,h2,e_given_d))


e = all_combos[:,0].reshape(-1,1)
h1 = all_combos[:,1].reshape(-1,1)
h2 = all_combos[:,2].reshape(-1,1)
e_given_d = all_combos[:,3].reshape(-1,1)
h2_given_e_x_e_given_d = ((.97*h2/e)*e_given_d).reshape(-1,1)


h2_given_not_e = (.03*h2/(1-e)).reshape(-1,1)


not_e_given_d = (1-e_given_d).reshape(-1,1)


max2 = np.maximum(h2_given_not_e,not_e_given_d)


ex_power_2 = (h2_given_e_x_e_given_d-max2)/(h2_given_e_x_e_given_d+max2)


h1_given_e_x_e_given_d = ((1*h1/e)*e_given_d).reshape(-1,1)


h1_given_not_e = (0*h1/(1-e)).reshape(-1,1)


max1 = np.maximum(h1_given_not_e,not_e_given_d)


ex_power_1 = (h1_given_e_x_e_given_d-max1)/(h1_given_e_x_e_given_d+max1)


initial_important_combos = np.hstack((e,h1,h2,e_given_d,ex_power_1,ex_power_2))



sufficient_combos = np.delete(initial_important_combos, np.where(e+.00001>.97),0)
sufficient_combos1 = np.delete(sufficient_combos, np.where(h1+.00001>(.97/.03)*(1-e_given_d)*(1-e)),0)


print(sufficient_combos1)

运行程序时,足够的_combos1包含子数组

[0.73 0.73 0.98 0.99 0.98 0.84422845]

但是,.73>(。97 / .03)(1-.99)(1-.73)=。0873。因此,据我所理解,上面的代码应删除此数组。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

刚刚解决了这个问题,问题是我使用的是向量的名称,而不是np.where范围内的矩阵列。需要用initial_important_combos [:,0]替换“ e”。