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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -