numpy.find() in Python (original) (raw)
Last Updated : 28 Nov, 2018
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 with the lowest index of found sub-string.
Code #1:
import
numpy as np
arr
=
[
'vdsdsttetteteAAAa'
,
'AAAAAAAaattttds'
,
'AAaaxxxxtt'
,
'AAaaXDSDdscz'
]
print
(
"arr : "
, arr)
print
(
"\nfind of 'tt'"
, np.char.find(arr,
'tt'
))
print
(
"find of 'tt'"
, np.char.find(arr,
'tt'
, start
=
0
))
print
(
"find of 'tt'"
, np.char.find(arr,
'tt'
, start
=
8
))
Output:
arr : ['vdsdsttetteteAAAa', 'AAAAAAAaattttds', 'AAaaxxxxtt', 'AAaaXDSDdscz']
find of 'tt' [ 5 9 8 -1] find of 'tt' [ 5 9 8 -1] find of 'tt' [ 8 9 8 -1]
Code #2:
import
numpy as np
arr
=
[
'vdsdsttetteteAAAa'
,
'AAAAAAAaattttds'
,
'AAaaxxxxtt'
,
'AAaaXDSDdscz'
]
print
(
"\nfind of 'Aa'"
, np.char.find(arr,
'Aa'
))
print
(
"find of 'Aa'"
, np.char.find(arr,
'Aa'
, start
=
8
))
Output:
find of 'Aa' [15 6 1 1] find of 'Aa' [15 -1 -1 -1]
Similar Reads
- 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
- numpy.info() function in Python In Numpy we can get all the information about the function, class, or module like what will the parameter and what will be the type of the return value with the help of numpy.info() function. This function returns the help information for a function, class, or module. Syntax: numpy.info(numpy.info(o 1 min read
- numpy.who function - Python numpy.who() function print the NumPy arrays in the given dictionary. Syntax : numpy.who(vardict = None) Parameters : vardict : [dict, optional] A dictionary possibly containing ndarrays. Return : Returns ‘None’. If there is no dictionary passed in or vardict is None then returns NumPy arrays in the 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
- numpy.argwhere() in Python 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 : # Python progra 1 min read
- numpy.roots() function - Python numpy.roots() function return the roots of a polynomial with coefficients given in p. The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by: p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n] Syntax : numpy.roots(p) Parame 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
- re.findall() in Python re.findall() method in Python helps us find all pattern occurrences in a string. It's like searching through a sentence to find every word that matches a specific rule. We can do this using regular expressions (regex) to create the pattern and then use re.findall() to get a list of matches. Let's sa 2 min read
- numpy.find_common_type() function - Python numpy.find_common_type() function determine common type following standard coercion rules. Syntax : numpy.find_common_type(array_types, scalar_types) Parameters : array_types : [sequence] A list of dtypes or dtype convertible objects representing arrays. scalar_types : [sequence] A list of dtypes or 1 min read
- numpy.issubclass_() function – Python numpy.issubclass_() function is used to determine whether a class is a subclass of a second class. Syntax : numpy.issubclass_(arg1, arg2) Parameters : arg1 : [class] Input class. True is returned if arg1 is a subclass of arg2. arg2 : [class or tuple of classes] Input class. If a tuple of classes, Tr 1 min read