0

I have a numpy array that has a shape of (2,60). Some of the numbers in the first row exceed 30 and I want to filter columns for which the value of the first row is less than 30.

I tried array = array[array < 30] #but that doesn't work 

An example of my array is

array = np.array([[30,40,12,12,10,2,30,40],[2,5,75,67,89,5,3,4]]) 

Expected output:

array = [[12 12 10 2]
       [75 67 89 5]]
Ehsan
  • 12,072
  • 2
  • 20
  • 33
  • Your use case is not at all clear. You say that you have a 2D NumPy array, but you show two unrelated lists. Please repeat [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). – Prune Apr 08 '21 at 00:17
  • What do you want the behavior to be if a different amount of numbers are removed from the first row of the array than the second? – duckboycool Apr 08 '21 at 00:17
  • @prune maybe I'm not stating it correctly sorry, I'm just saying that my 2D array has x and y data points. Sorry english is not my first language – phys_birthdaycake Apr 08 '21 at 00:19
  • @duckboycool my 2D numpy array has x and y components and I want to get rid of some of the x data points but with that I want to remove the corresponding y data points – phys_birthdaycake Apr 08 '21 at 00:21
  • It's not simply that you're not stating it correctly; the only work you show is incompatible with the data you provide. – Prune Apr 08 '21 at 00:21
  • Please supply the expected [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) (MRE). We should be able to copy and paste a contiguous block of your code, execute that file, and reproduce your problem along with tracing output for the problem points. This lets us test our suggestions against your test data and desired output. – Prune Apr 08 '21 at 00:22
  • @prune I edited, does that make more sense? – phys_birthdaycake Apr 08 '21 at 00:27

1 Answers1

0

You are looking for this:

array[:,array[0]<30]

output:

array([[12, 12, 10,  2],
       [75, 67, 89,  5]])
Ehsan
  • 12,072
  • 2
  • 20
  • 33