1

My program contains many different NumPy arrays, with various data inside each of them. An example of an array is:

x = [5, 'ADC01', Input1, 25000], # Where [TypeID, Type, Input, Counts]
    [5, 'ADC01', Input2, 40000]

From separate arrays I can retrieve the value of Type and Input. I then need to say

Counts = x[0,3] where Type = 'ADC01' and Input = 'Input2'

Obviously it would not be wrote like this. For the times that I have only needed to satisfy one condition, I have used:

InstType_ID = int(InstInv_Data[InstInv_Data[:,glo.inv_InstanceName] == Instrument_Type_L][0,glo.inv_TypeID])

Here, it looks in array(InstInv_Data) at the 'InstanceName' column and finds a match to Instrument_Type. It then assigns the 'TypeID' column to InstType_ID. I basically want to add an and statement so it also looks for another matching piece of data in another column.

Edit: I just thought that I could try and do this in two separate steps. Returning both Input and Counts columns where Type-Column = Type. However, I am unsure of how to actually return two columns, instead of a specific one. Something like this:

Intermediate_Counts = (InstDef_Data[InstDef_Data[:,glo.i_Type] == Instrument_Type_L][0,(glo.i_Input, glo.i_Counts])

1 Answer 1

7

You could use a & b to perform element-wise AND for two boolean arrays a, b:

selected_rows = x[(x[:,1] == 'ADC01') & (x[:,2] == 'Input2')]

Similarly, use a | b for OR and ~a for NOT.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I attempted to do something similar to this but I got confused with where to put brackets. That worked great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.