我维护了一些代码,我遇到了类似的东西:
travel_time_vec = np.zeros(...)
for v in some_indexes: # some_indexes is a list of row indexes
traveltimes = traveltime_2d_array[v, list_of_column_indexes]
best_index = np.argmin(traveltimes)
travel_time_vec[v] = traveltimes[best_index]
我想放弃 for 循环并立即执行以下所有操作 - 但天真地要求traveltime_2d_array[some_indexes, list_of_column_indexes]
结果:
{IndexError} 形状不匹配:索引数组无法与形状 (4,) (8,) 一起广播