4 ms·
> The numpy version makes it clear that you are using random integers, not floating point values. That's also completely clear in the Julia version, if you lea
by timholy 11y ago
> The numpy version makes it clear that you are using random integers, not floating point values.
That's also completely clear in the Julia version, if you learn a little Julia.
> In numpy, most operations are element-wise by default, because the result would be ambiguous or not useful otherwise.
This is why I think the Julia approach is better. If I write `a == 7`, am I testing whether `a` is 7 or whether any of the elements of `a` are 7?
- jdreaver 11y ago> That's also completely clear in the Julia version, if you learn a little Julia. In every language I've used, the default is for a "rand" function to return random floats between 0 and 1, and given arguments it returns floats between the arguments. I don't think it has to do with learning Julia, it is just that including "integer" in the function name makes it clear the function returns integers. > This is why I think the Julia approach is better. If I write `a == 7`, am I testing whether `a` is 7 or whether any of the elements of `a` are 7? I think this is more of a comment about mixing arrays and scalars in a dynamic language. I made my comment assuming you are performing operations on arrays. If you are comparing two arrays, I think the default of element-wise operations makes more sense.
- KenoFischer 11y agoIn julia the rand function is more general in that it samples from a distribution, which you can pass as the first argument (defaulting to uniform on [0,1]). Since the first argument is an integer range, you get an integer value.