Or you can use an anonymous function julia> filter(x->x!=0, A) 4-element Array{Int64,1}: 1 2 4 5
the `do` syntax is exactly equivalent, but more convenient when you have a longer function body julia> filter(A) do x x != 0 end 4-element Array{Int64,1}: 1 2 4 5 Regards Ivar kl. 16:18:05 UTC+1 mandag 3. november 2014 skrev João Felipe Santos følgende: > > You just need to write a function that returns false for the elements you > want to filter out. Here’s an example that does what you want: > > julia> myfilter(x) = x != 0 > myfilter (generic function with 1 method) > > julia> A = [1, 2, 0, 4, 5, 0] > 6-element Array{Int64,1}: > 1 > 2 > 0 > 4 > 5 > 0 > > julia> filter(myfilter, A) > 4-element Array{Int64,1}: > 1 > 2 > 4 > 5 > > > On Nov 3, 2014, at 10:15 AM, Zahirul ALAM <zahiru...@gmail.com > <javascript:>> wrote: > > > > The documentation says: > > > > filter(function, collection) > > Return a copy of collection, removing elements for which function is > false. For associative collections, > > the function is passed two arguments (key and value). > > > > how to write the fucntion? I am trying to get elements which are > nonzero. Any Help is much appreciated! > >