Find the number of occurrences of a sequence in a NumPy array Last Updated : 05 Sep, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The sequence is consisting of some elements in the form of a list and we have to find the number of occurrences of that sequence in a given NumPy array. This can be done easily by checking the sequence for every iteration of ndarray. But this leads to higher time so we use the concept of NumPy methods. Example : Arr = [[2,8,9,4], [9,4,9,4], [4,5,9,7], [2,9,4,3]] and the seq = [9,4] then output is 4. Here, first row [2,8,9,4] contains one [9,4] sequence so output = 1. second row [9,4,9,4] contains two [9,4] sequence so output = 1+2 = 3. third row [4,5,9,7] contains no [9,4] sequence so output = 3+0 = 3. fourth row [2,9,4,3] contains one [9,4] sequence so output = 3+1 = 4. Below is the implementation with an example : Python3 # importing package import numpy # create numpy array arr = numpy.array([[2, 8, 9, 4], [9, 4, 9, 4], [4, 5, 9, 7], [2, 9, 4, 3]]) # Counting sequence output = repr(arr).count("9, 4") # view output print(output) Output : 4 Comment More infoAdvertise with us Next Article Find unique rows in a NumPy array D deepanshu_rustagi Follow Improve Article Tags : Python Python-numpy Python numpy-program Python numpy-arrayManipulation Practice Tags : python Similar Reads Count the occurrence of a certain item in an ndarray - Numpy In this article, the task is to find out how to count the occurrence of a certain item in an nd-Array in Python. Example Array = [[ 0 1 2 3] [ 4 5 2 7] [ 8 2 10 11]] Input: element = 2 Output: 3 timesCount the occurrence of a certain item in an array using a loop Here we are using a loop to count th 3 min read Find unique rows in a NumPy array Finding unique rows means removing duplicate rows from a 2D array so that each row appears only once. For example, given [[1, 2], [3, 4], [1, 2], [5, 6]], the unique rows would be [[1, 2], [3, 4], [5, 6]]. Letâs explore efficient ways to achieve this using NumPy.Using np.unique(axis=0)np.unique(axis 3 min read Python | Count occurrences of an element in a Tuple In this program, we need to accept a tuple and then find the number of times an item is present in the tuple. This can be done in various ways, but in this article, we will see how this can be done using a simple approach and how inbuilt functions can be used to solve this problem. Examples: Tuple: 3 min read How to find the Index of value in Numpy Array ? In this article, we are going to find the index of the elements present in a Numpy array.Using where() Methodwhere() method is used to specify the index of a particular element specified in the condition.Syntax: numpy.where(condition[, x, y])Example 1: Get index positions of a given valueHere, we fi 5 min read Counting the number of non-NaN elements in a NumPy Array In this article, we are going to see how to count the number of non-NaN elements in a NumPy array in Python. NAN: It is used when you don't care what the value is at that position. Maybe sometimes is used in place of missing data, or corrupted data. Method 1: Using Condition In this example, we wil 3 min read Find the position of number that is multiple of certain number In this type of question, a number is given and we have to find the position or index of all multiples of that number. For doing this question we use a function named numpy.argwhere(). Syntax: numpy.argwhere(array) Example 1: Sometimes we need to find the indexes of the element that are divisible b 1 min read Like