0

I'm working using python 3.x on Windows 10. I have a numpy array of size 1848. I need to delete even numbers from this array. I tried following thing

len=arr.size

for i in range(1,len-1):
  if (arr[i]%2==0):
    result=np.where(arr==arr[i])
    result=int(result[0])
    np.delete(arr,result,axis=0)
    len=len-1

But it's not working. Can you suggest me how to do this?

Sonia
  • 464
  • 10
  • 21
  • The duplicate applies to almost all iterables. The simple answer is that you don't -- rather, you make a new sequence (array) by filtering for the values you want to keep. – Prune Aug 27 '19 at 16:13

1 Answers1

4
import numpy as np

a = np.random.randint(10, size=10)
[4 3 9 9 9 4 3 4 3 2] 

a[a%2!=0]
[3, 9, 9, 9, 3, 3]
galaxyan
  • 5,944
  • 2
  • 19
  • 43