mds_array_manipulation.search_array

Module Contents

Functions

search_array(→ int)

Search for elem in a numpy array. This function is

mds_array_manipulation.search_array.search_array(arr: numpy.array, elem: int | float | str) int[source]

Search for elem in a numpy array. This function is specifically designed to work only with 1-dimensional arrays.

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. This function does not support multi-dimensional arrays and will raise a ValueError if a multi-dimensional array is passed as input.

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