remove the zeros from an array with a function Python -


here's deal, have array of multiples elements half of being zeros. want remove these zeros using function instead of traditional x=x[x!=0].

i tried:

def funct(x,y):     x=x[x!=0]     y=y[y!=0] 

but output same variable had before execute function. array multiple zeros.

i'm new python sorry if question sound ridiculous.

thank much!

x[x!=0] returns new array, , assigned new array local variable x.

you can do:

def funct(x, y):     x = x[x!=0]     y = y[y!=0]     # here     return x,y a, b = funct(a, b)  #assign returned value global variables 

Comments