numpy.argwhere() in Python (original) (raw)
Last Updated : 24 Dec, 2018
**numpy.argwhere()
**function is used to find the indices of array elements that are non-zero, grouped by element.
Syntax : numpy.argwhere(arr)
Parameters :
arr : [array_like] Input array.Return : [ndarray] Indices of elements that are non-zero. Indices are grouped by element.
Code #1 :
import
numpy as geek
in_arr
=
[[
2
,
0
,
7
], [
0
,
5
,
9
]]
print
(
"Input array : "
, in_arr)
out_arr
=
geek.argwhere(in_arr)
print
(
"Output indices of non zero array element: \n"
, out_arr)
Output:
Input array : [[2, 0, 7], [0, 5, 9]] Output indices of non zero array element: [[0 0] [0 2] [1 1] [1 2]]
Code #2 :
import
numpy as geek
in_arr
=
geek.arange(
8
).reshape(
4
,
2
)
print
(
"Input array : "
, in_arr)
out_arr
=
geek.argwhere(in_arr>
4
)
print
(
"Output indices greater than 4: \n"
, out_arr)
Output:
Input array : [[0 1] [2 3] [4 5] [6 7]] Output indices greater than 4: [[2 1] [3 0] [3 1]]
Similar Reads
- numpy.argsort() in Python numpy.argsort() is a function in NumPy that returns the indices that would sort an array. In other words, it gives you the indices that you would use to reorder the elements in an array to be in sorted order. Example: [GFGTABS] Python import numpy as geek a = geek.array([2, 0, 1, 5, 4, 1, 9]) print( 3 min read
- numpy.find() in Python numpy.core.defchararray.find(arr, substring, start=0, end=None): Finds the lowest index of the sub-string in the specified range. Parameters: arr : array-like or string to be searched. substring : substring to search for. start, end : [int, optional] Range to search in. Returns : An integer array wi 1 min read
- numpy.index() in Python numpy.core.defchararray.index(arr, substring, start=0, end=None): Finds the lowest index of the sub-string in the specified range But if substring is not found, it raises ValueError. Parameters: arr : array-like or string to be searched. substring : substring to search for. start, end : [int, option 1 min read
- Python | Numpy numpy.ndarray.__or__() With the help of Numpy numpy.ndarray.__or__() method, we can get the elements that is OR by the value that is provided as a parameter in numpy.ndarray.__or__() method. Syntax: ndarray.__or__($self, value, /) Return: self|value Example #1 : In this example we can see that every element is or by the v 1 min read
- numpy.where() in Python We will explore the basics of numpy.where(), how it works, and practical use cases to illustrate its importance in data manipulation and analysis. Syntax of numpy.where()Syntax :numpy.where(condition[, x, y]) Parameters condition: A condition that tests elements of the array.x (optional): Values fro 3 min read
- Python | Numpy ndarray.__ior__() With the help of Numpy ndarray.__ior__() method, we can get the elements that is OR by the value that is provided as a parameter in numpy.ndarray.__ior__() method. Syntax: ndarray.__ior__($self, value, /) Return: self|=value Example #1 : In this example we can see that every element is or by the val 1 min read
- Python | Numpy numpy.ndarray.__and__() With the help of Numpy numpy.ndarray.__and__() method, we can get the elements that is anded by the value that is provided as a parameter in numpy.ndarray.__and__() method. Syntax: ndarray.__and__($self, value, /) Return: self&value Example #1 : In this example we can see that every element is a 1 min read
- numpy.log10() in Python About : numpy.log10(arr, out = None, *, where = True, casting = 'same_kind', order = 'K', dtype = None, ufunc 'log10') : This mathematical function helps user to calculate Base-10 logarithm of x where x belongs to all the input array elements. Parameters : array : [array_like]Input array or object. 2 min read
- Python | Numpy ndarray.__iand__() With the help of Numpy ndarray.__iand__() method, we can get the elements that is anded by the value that is provided as a parameter in numpy.ndarray.__iand__() method. Syntax: ndarray.__iand__($self, value, /) Return: self&=value Example #1 : In this example we can see that every element is and 1 min read
- Python | Numpy ndarray.item() With the help of numpy.ndarray.item() method, we can fetch the data elements that is found at the given index on numpy array. Remember we can give index as one dimensional parameter or can be two dimensional. Parameters: *args : Arguments (variable number and type) -> none: This argument only works 1 min read