Cool, thanks. I had to change the return value to catch the all-NaN case: (cond (= 0 n) NaN :else (/ sum n))
On Wednesday, July 10, 2013 12:58:54 AM UTC-7, Mikera wrote: > > You could use ereduce (elementwise reduce) in core.matrix to do this. > Something like: > > (let [NaN Double/NaN > [sum n] (ereduce > (fn [[acc cnt] x] (if (Double/isNaN x) [acc cnt] [(+ > acc x) (inc cnt)])) > [0 0] > [0.0 1.0 NaN 2.0 NaN 3.0 4.0 NaN])] > (/ sum n)) > => 2.0 > > On Wednesday, 10 July 2013 05:03:55 UTC+1, Brian Craft wrote: >> >> Is there any way to do masked arrays (like numpy) with core.matrix, or >> another lib? I need to be able to, for example, compute a mean while >> skipping nan values, which is easily done with masked arrays. > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
