3 ms·
Yes, that example is easy, although you got it wrong, I said 100 random walks of length 1000, which should be (1000, 100) not (100, 1000). However, there are st
by rak1507 4y ago
Yes, that example is easy, although you got it wrong, I said 100 random walks of length 1000, which should be (1000, 100) not (100, 1000). However, there are still more 'moving parts' in numpy than in APL/J, you have to modify the tuple, and the axis, and other things. It all adds up when making lots of small iterations.
The modification you mentioned is straightforward in any array language. Here is what you mentioned in APL (I know APL more than J but I'm sure the J would be basically the same):
⊃⍤⍸⍤1⊢0=+\¯1*?100 1000⍴2
This is the number of steps to return to 0 for each of 100 random walks of length 1000. (It is then easy to analyse the frequency/average/etc with only a few more characters)
- mgraczyk 4y agoInteresting, but I guess I'd have to learn APL or J to compare. Without understanding what those symbols mean, it seems much less like "math" than the numpy version. 1 + np.min(np.argwhere(running_sum[1:] == 0), axis=0)