HNHacker News
TopNewBestAskShowJobs

oiuswv

2 karma · joined November 12, 2015

submissionscomments
oiuswv··on Julia Computing Granted $600k by Moore Foundation
Here, I'll use logical indexing to pull out all the positive even numbers from this array of random integers:

Numpy:

  a = np.random.random_integers(low = -100, high = 100, size = (100,))
  a[np.logical_and(a % 2 == 0, a > 0)
(or a[(a % 2 == 0) * (a > 0)])

Logical indexing is used everywhere in numerical computing. Using functions like logical_and() or boolean multiplication or addition is more difficult to follow than Matlab or Julia.

Julia:

  a = rand(-100:100, 100)
  a[(a % 2 .== 0) & (a .> 0)]
Well, that's beautiful. Element-wise operations are prefixed with "."