我的程序包含许多不同的NumPy数组,每个数组中都有不同的数据。数组的一个例子是:
x = [5, 'ADC01', Input1, 25000], # Where [TypeID, Type, Input, Counts]
[5, 'ADC01', Input2, 40000]
我可以从单独的数组中检索Type
和Input
的值。然后我需要说
Counts = x[0,3] where Type = 'ADC01' and Input = 'Input2'
显然不会像这样写。在我只需要满足一个条件的时候,我使用了:
InstType_ID = int(InstInv_Data[InstInv_Data[:,glo.inv_InstanceName] == Instrument_Type_L][0,glo.inv_TypeID])
在这里,它在'InstanceName‘列中查找数组(InstanceName),并找到与Instrument_Type匹配的值。然后它将'TypeID‘列赋值给InstType_ID,我基本上希望添加一个and
语句,这样它也会在另一个列中查找另一个匹配的数据。
编辑:我只是想,我可以尝试在两个不同的步骤。返回Input
和Counts
列,其中Type-Column = Type
。但是,我不知道如何实际返回两个列,而不是一个特定的列。就像这样:
Intermediate_Counts = (InstDef_Data[InstDef_Data[:,glo.i_Type] == Instrument_Type_L][0,(glo.i_Input, glo.i_Counts])
发布于 2017-01-27 08:06:01
您可以使用a & b
对元素执行操作,并对两个布尔数组( a
,b
)执行。
selected_rows = x[(x[:,1] == 'ADC01') & (x[:,2] == 'Input2')]
同样,对OR使用a | b
,对NOT使用~a
。
https://stackoverflow.com/questions/41898000
复制相似问题