Get row numbers of NumPy array having element larger than X Last Updated : 11 Oct, 2020 Comments Improve Suggest changes Like Article Like Report Let's see how to getting the row numbers of a numpy array that have at least one item is larger than a specified value X. So, for doing this task we will use numpy.where() and numpy.any() functions together. Syntax: numpy.where(condition[, x, y]) Return: [ndarray or tuple of ndarrays] If both x and y are specified, the output array contains elements of x where condition is True, and elements from y elsewhere. Syntax: numpy.any(a, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c) Return: [ndarray, optional]Output array with same dimensions as Input array, Placed with result Example : Arr = [[1,2,3,4,5], [10,-3,30,4,5], [3,2,5,-4,5], [9,7,3,6,5]] and X = 6 then output is [ 0, 2 ]. Here, [[1,2,3,4,5], no element is greater than 6 so output is [0]. [10,-3,30,4,5], 10 is greater than 6 so output is [0]. [3,2,5,-4,5], no element is greater than 6 so output is [0, 2]. [4,7,3,6,5]] 7 is greater than 6 so output is [0, 2]. Below is the implementation: Python3 # importing library import numpy # create numpy array arr = numpy.array([[1, 2, 3, 4, 5], [10, -3, 30, 4, 5], [3, 2, 5, -4, 5], [9, 7, 3, 6, 5] ]) # declare specified value X = 6 # view array print("Given Array:\n", arr) # finding out the row numbers output = numpy.where(numpy.any(arr > X, axis = 1)) # view output print("Result:\n", output) Output: Given Array: [[ 1 2 3 4 5] [10 -3 30 4 5] [ 3 2 5 -4 5] [ 9 7 3 6 5]] Result: (array([1, 3], dtype=int64),) Comment More infoAdvertise with us Next Article Get row numbers of NumPy array having element larger than X D deepanshu_rustagi Follow Improve Article Tags : Python Python-numpy Python numpy-Indexing Practice Tags : python Similar Reads NumPy ndarray.size() Method | Get Number of Elements in NumPy Array The ndarray.size() method returns the number of elements in the NumPy array. It works the same as np.prod(a.shape), i.e., the product of the dimensions of the array. Example Python3 import numpy as np arr = np.zeros((3, 4, 2), dtype = np.complex128) gfg = arr.size print (gfg) Output : 24Syntax Synta 1 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 How to get the number of dimensions of a matrix using NumPy in Python? In this article, we will discuss how to get the number of dimensions of a matrix using NumPy. It can be found using the ndim parameter of the ndarray() method. Syntax: no_of_dimensions = numpy.ndarray.ndim Approach: Create an n-dimensional matrix using the NumPy package.Use ndim attribute available 3 min read Find indices of elements equal to zero in a NumPy array Sometimes we need to find out the indices of all null elements in the array. Numpy provides many functions to compute indices of all null elements. Method 1: Finding indices of null elements using numpy.where() This function returns the indices of elements in an input array where the given conditio 3 min read NumPy| How to get the unique elements of an Array To find unique elements of an array we use the numpy.unique() method of the NumPy library in Python. It returns unique elements in a new sorted array. Example: Python3 import numpy as np arr = np.array([1, 2, 3, 1, 4, 5, 2, 5]) unique_elements = np.unique(arr) print(unique_elements) Output: [1 2 3 4 2 min read NumPy ndarray.__abs__() | Find Absolute Value of Elements in NumPy Array The ndarray.__abs__() method returns the absolute value of every element in the NumPy array. It is automatically invoked when we use Python's built-in method abs() on a NumPy array. Example Python3 import numpy as np gfg = np.array([1.45, 2.32, 3.98, 4.41, 5.55, 6.12]) print(gfg.__abs__()) Output[ 1 1 min read How to delete last N rows from Numpy array? In this article, we will discuss how to delete the last N rows from the NumPy array. Method 1: Using Slice Operator Slicing is an indexing operation that is used to iterate over an array.  Syntax: array_name[start:stop] where start is the start is the index and stop is the last index. We can also do 4 min read How to get the n-largest values of an array using NumPy? Let's see the program for how to get the n-largest values of an array using NumPy library. For getting n-largest values from a NumPy array we have to first sort the NumPy array using numpy.argsort() function of NumPy then applying slicing concept with negative indexing. Syntax: numpy.argsort(arr, ax 2 min read Test whether the elements of a given NumPy array is zero or not in Python In numpy, we can check that whether none of the elements of given array is zero or not with the help of numpy.all() function. In this function pass an array as parameter. If any of one element of the passed array is zero then it returns False otherwise it returns True boolean value. Syntax: numpy.al 2 min read How to check whether the elements of a given NumPy array is non-zero? In NumPy with the help of any() function, we can check whether any of the elements of a given array in NumPy is non-zero. We will pass an array in the any() function if it returns true then any of the element of the array is non zero if it returns false then all the elements of the array are zero. S 1 min read Like