-1

I have 12 numpy array that contains arounf 1000 values within each one. Some of the values have a star around them and indicating that I need to delete the value from the array. Others don't and it is difficult to check where these are. Code similar (but smaller example) below:

nums1 = np.array([654, 648, 213, *684*, 516, 654, *987*, 321])
nums2 = np.array([68, 89, 36, 879, 78, 213, 89, 79])
nums3 = np.array([432, *87*, 809, 312, 76, *890*, 234, 32])

Is there any way to test each of these and get an array of the indicies such that I can delete the values and their corresponding partners in my other arrays? Again this is an example, my arrays are much larger. My ideal output would be something similar to:

bad_values_nums1 = np.array([3, 6])
bad_values_nums2 = np.array([])
bad_values_nums3 = np.array([1, 5])
  • 2
    How do you add the stars? – Reti43 Mar 21 '20 at 22:42
  • 1
    This is not valid Python syntax. Did you mean to use string values? Like `np.array(['432', '*87*', '809')`? – Tomerikoo Mar 21 '20 at 22:44
  • Someone else just asked about starred values, https://stackoverflow.com/questions/60793306/how-to-check-the-type-of-the-values-within-a-numpy-array. Same confusion as to what are strings and numbers. – hpaulj Mar 22 '20 at 03:35

1 Answers1

0

Assuming you mean to have an array of strings, you can do something like the following:

nums1 = np.array(['654','648', '213', '*684*', '516', '654', '*987*', '321'])
bad_values_nums1 = [i for i,v in enumerate(nums1) if v[0] == '*' and v[-1] == '*']
Dominic D
  • 1,778
  • 2
  • 5
  • 12