5 examples of 'get index of element in array python' in Python

Every line of 'get index of element in array python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
62def find_index(self, e):
63 for i in range(self._size):
64 if self._data[i] == e:
65 return i
66 return -1
4def find(arr, elem):
5 lo = 0
6 hi = len(arr) - 1
7 while lo < hi:
8 mid = (hi + lo) // 2
9 first = arr[lo]
10 middle = arr[mid]
11 last = arr[hi]
12
13 if first <= middle and elem >= first and elem <= middle:
14 return binary_search(arr, elem, lo, mid)
15 elif last >= middle and elem >= middle and elem <= last:
16 return binary_search(arr, elem, mid+1, hi)
17 elif elem >= first and elem <= middle:
18 hi = mid
19 else:
20 lo = mid + 1
21
22 if arr[lo] == elem:
23 return lo
24 return None
17def at_i(array, i=0):
18 return [a[i] for a in array]
220def getInd(value, array):
221 """Return closest index (rounded down) of a value from sorted array."""
222 ind = np.abs(array-value).argmin()
223 return int(ind)
563def descr_getitem(self, space, w_idx):
564 "x.__getitem__(y) <==> x[y]"
565 if not space.isinstance_w(w_idx, space.w_slice):
566 idx, stop, step = space.decode_index(w_idx, self.len)
567 assert step == 0
568 return self.w_getitem(space, idx)
569 else:
570 return self.getitem_slice(space, w_idx)

Related snippets