mds_array_manipulation.search_array
Module Contents
Functions
|
Search for elem in a numpy array. |
- mds_array_manipulation.search_array.search_array(arr, elem)[source]
Search for elem in a numpy array.
- Parameters:
arr (numpy.array) – The numpy array to search
elem (numeric or string) – Object to search for in the array
- Returns:
Index of the first occurence of the element in the array, -1 if not found
- Return type:
int
- Raises:
TypeError – If the input is not a numpy array, or does not contain numeric or string values.
ValueError – If the input array is not 1-dimensional.
Examples
>>> import numpy as np >>> from mds_array_manipulation.mds_array_manipulation import search_array >>> arr = np.array([20, 10, 20, 30, 50, 90, 60]) >>> search_array(arr, 50) 4 >>> search_array(arr, 100) -1 >>> search_array(arr, 20) 0