0

i have 3 array a and b with the same size

a= [1,20,0,3,9,9,9,55]
b= [1,5,6,9,9,9,9,55]

i need to delete the element 0 from a and delete the element in the same index in the array b will look like this:

    a= [1,20,3,9,9,9,55]
    b= [1,5,9,9,9,9,55]



import numpy as np
import math
a = np.array([1, 0,3])
b = np.array([5, 6,9])


c= np.vstack((a,b)).T
c= c[(c[:,0]<>0)]
k= c[:,0]
f= c[:,1]
r= math.sqrt(np.mean(np.power(((k - f) / k),2)))
r

my code is working but i did not like it do you have any other propositions ?

Amal Kostali Targhi
  • 907
  • 3
  • 11
  • 22
  • 3
    There's a dedicated site for code reviews http://codereview.stackexchange.com – Tae Oct 28 '17 at 01:07

1 Answers1

1

if you have a, b, c as numpy arrays

valid_idx = (a != 0)
b = b[valid_idx]
c = c[valid_idx]
user1620443
  • 784
  • 3
  • 14