Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • $\begingroup$ 1## & (for Times) from @Mr.Wizard somewhere on this site. $\endgroup$ Commented Jan 2, 2018 at 5:54
  • 2
    $\begingroup$ Slightly tangential, but if binm is given as a SparseArray then I get almost an order of magnitude speed up for countZ. $\endgroup$ Commented Jan 2, 2018 at 10:11
  • 2
    $\begingroup$ @aardvark2012 First, I was somewhat surprised but did you count in the conversion into a SparseArray? But thinking of it, I recalled that the constructor for sparse arrays has to count the nonzero values. So if you don't count in the construction time, then Times @@ Dimensions[binm] - Length[binm["NonzeroValues"] returns the result for arbitrary large SparseArrays that fit into memory. $\endgroup$ Commented Jan 2, 2018 at 16:25
  • $\begingroup$ This 1 ## & @@ in the code is really cool +1! $\endgroup$ Commented Jan 2, 2018 at 18:31
  • $\begingroup$ @HenrikSchumacher No, I didn't count the conversion time (which is bad). I was thinking more that if the original binarym could be constructed as a SparseArray from the outset with no additional cost then it could be well worth it. OP didn't mention how the array was built, so that may not be possible (which is why my comment is "tangential"). I forgot about NonzeroValues, though, which would be a pretty awesome way to do this, if the OP could get it as a SparseArray. $\endgroup$ Commented Jan 2, 2018 at 22:17