I'm new to Numpy and it's been a while writing python.
I'm struggeling to find multiple strings in a Numpy array which was sliced.
My data:
string0 = "part0-part1-part2-part3-part4"
string1 = "part5-part6-part9-part7-part8"
string2 = "part5-part6-part1-part8-part7"
Sliced in to each part and combined to one array again to have it all in one place.
stringsraw = np.array([[string0], [string1], [string2]])
stringssliced = np.array(np.char.split(stringsraw, sep = '-').tolist())
stringscombined = np.squeeze(np.dstack((stringsraw, stringssliced)))
Results in:
[['part0-part1-part2-part3-part4' 'part0' 'part1' 'part2' 'part3' 'part4']
['part5-part6-part9-part7-part8' 'part5' 'part6' 'part9' 'part7' 'part8']
['part5-part6-part1-part7-part8' 'part5' 'part6' 'part1' 'part8' 'part7']]
Want to find the indices of 'part1' and 'part7'
np.where((stringscombined[2] == "part1") & (stringscombined[2] == "part7"))
The result is nothing. Can anyone explain why the result is not [3,4]?
Thought there would be a nicer way to not for loop through everything.
The "whished" query/result would be:
np.where((stringscombined == "part6") & (stringscombined == "part7"))
= array[[1,2,4]
[2,2,5]]
any help appreciated