0

good evening. i wanted to iterate an array and delete its indexes every other. or maybe put those indexes i want in a new array.

I tried

Processed_Data=np.array([i for i in Engleashed_Serch_Results if (i%2)])

but there is an unsupported operand type(s) error on division.

Engleashed_Serch_Results is another NumPy array

  • What is `Engleashed_Serch_Results`? – Talha Tayyab Mar 17 '23 at 14:12
  • 1
    Try `Processed_Data=np.array([Engleashed_Serch_Results[i] for i in range(len(Engleashed_Serch_Results)) if not (i % 2)])`. – Matt Pitkin Mar 17 '23 at 14:20
  • @GodIsOne; im sorry for my terrible naming. `Engleashed_Serch_Results` is an other numpy array –  Mar 17 '23 at 14:22
  • @MattPitkin;i tried your code but thats not working currect,there is about 160 values in my `Engleashed_Serch_Results` but in "Processed_Data" there is just 36.but there should be about 80. –  Mar 17 '23 at 14:45
  • 1
    What shape is your `Engleashed_Serch_Results` array? I was assuming it was 1-dimensional, in which case my code should work fine. Also, a much simpler version of my answer would be to use [slice notation](https://stackoverflow.com/a/509295/1862861) and do `Processed_Data = Engleashed_Serch_Results[::2]` (again, provided the data is 1d). – Matt Pitkin Mar 17 '23 at 15:52
  • @MattPitkin it is one dimensional but there is some fields empty next to each other i think this made problem because in this part it left all other indexes empty. my `Engleashed_Serch_Results` looks like:[... "2400000" , "4600000" , "11000000" , "" , "" , "" , "38000" ...] –  Mar 17 '23 at 16:39
  • @MattPitkin, the slicing is not working too, even gave it start and stop point but it gives up when it recives null or 0 for seveal times –  Mar 17 '23 at 19:47
  • Could you provide the output of `print(Engleashed_Serch_Results.shape)` and `print(Engleashed_Serch_Results.dtype)`? – Matt Pitkin Mar 17 '23 at 22:36
  • @MattPitkin this is what it prints for those two lines:`(165,) –  Mar 18 '23 at 10:12
  • The `""` are just being held as strings, so should not effect things. I've really no idea why the slicing is not working for you. If I just do something simple like: `import numpy as np; x = ["sadkjkbfd lldjaslhd asdjh sdalhd"]; a = np.array(165 * x)`, which produces an array with shape `(165,)` and type `", it also works fine too. – Matt Pitkin Mar 20 '23 at 11:26
  • "" i means "" not any thing inside it. idont know but thank you i solved it actualy i deleted all "" an then iserted two 0 s in array.... i know its not the right way to do it but its efffective :/ –  Mar 20 '23 at 11:39

0 Answers0