Check whether a Numpy array contains a specified row
In this article we will learn about checking a specified row is in NumPy array or not. If the given list is present in a NumPy array as a row then the output is True else False. The list is present in a NumPy array means any row of that numpy array matches with the given list with all elements in given order. This can be done by using simple approach as checking for each row with the given list but this can be easily understood and implemented by using inbuilt library functions numpy.array.tolist().
Returns: The possibly nested list of array elements.
Arr = [[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15], [16,17,18,19,20]]
and the given lists are as follows :
lst = [1,2,3,4,5] True, as it matches with the row 0.
[16,17,20,19,18] False, as it doesn’t match with any row.
[3,2,5,-4,5] False, as it doesn’t match with any row.
[11,12,13,14,15] True, as it matches with the row 2.
Below is the implementation with an example :
[[ 1 2 3 4 5] [ 6 7 8 9 10] [11 12 13 14 15] [16 17 18 19 20]] True False False True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course