3 ms·
So concretely, consider the following problem. I'll tell you the python way, maybe you could tell me the J way. I want to simulate a random walk, run a statisti
by yummyfajitas 12y ago
So concretely, consider the following problem. I'll tell you the python way, maybe you could tell me the J way. I want to simulate a random walk, run a statistical test on it at each time, then find the first time when the test returns positive.
In numpy:
data = cumsum(bernoulli(p).rvs(1024*16))
test_statistic = special.xlogy(data, p) * ... other stuff...
first_pos = where(test_statistic > b)[0][0]
bernoulli(p).rvs(1024*16) generates a random array of the form [0,1,0,0,1,0,1], and where(...) returns an array of places where the condition is true.
If we translated this code to J, would it be idiomatic?
(Incidentally it does happen to be wildly inefficient - a simple for loop (in C) with no arrays is about 100x faster.)