5 ms·
It means the same thing in MATLAB and numpy: Z = np.array([[1,2,3]]) W = Z + Z.T print(W) Gives: [[2 3 4] [3 4 5] [4 5 6]] It's called b
by quietbritishjim 10mo ago
It means the same thing in MATLAB and numpy:
Z = np.array([[1,2,3]])
W = Z + Z.T
print(W)
Gives:
[[2 3 4]
[3 4 5]
[4 5 6]]
It's called broadcasting [1]. I'm not a fan of MATLAB, but this is an odd criticism.
[1] https://numpy.org/devdocs/user/basics.broadcasting.html#general-broadcasting-rules https://numpy.org/devdocs/user/basics.broadcasting.html#gene...
- adgjlsfhk1 10mo agoOne of the really nice things Julia does is make broadcasting explicit. The way you would write this in Julia is Z = [1,2,3] W = Z .+ Z' # note the . before the + that makes this a broadcasted This has 2 big advantages. Firstly, it means that users get errors when the shapes of things aren't what they expected. A DimmensionMismatch error is a lot easier to debug than a silently wrong result. Secondly, it means that julia can use `exp(M)` etc to be a matrix exponential, while the element-wise exponential is `exp.(M)`. This allows a lot of code to naturally work generically over both arrays and scalars (e.g. exp of a complex number will work correctly if written as a 2x2 matrix)