| ▲ | BobbyTables2 a day ago | |||||||
What does it even mean to add a 1x3 matrix to a 3x1 matrix ? | ||||||||
| ▲ | freehorse a day ago | parent | next [-] | |||||||
This is about how array operations in matlab work. In matlab, you can write things such as
In this case, the operation `+ 1` is applied in all columns of the array. In this exact manner, when you add a (1 x m) row and a (n x 1) column vector, you add the column to each row element (or you can view it the other way around). So the result is as if you repeat your (n x 1) column m times horizontally, giving you a (n x m) matrix, do the same for the row vertically n times giving you another (n x m) matrix, and then you add these two matrices. So basically adding a row and a column is essentially a shortcut for repeating adding these two (n x m) matrices (and runs faster than actually creating these matrices). This gives a matrix where each column is the old column plus the row element for that row index. For example
A very practical example is, as I mentioned, getting all differences between the elements of a time series by writing `S - S'`. Another example, `(1:6)+(1:6)'` gives you the sums for all possible combinations when rolling 2 6-sided dice.This does not work only with addition and subtraction, but with dot-product and other functions as well. You can do this across arbitrary dimensions, as long as your input matrices non-unit dimensions do not overlap. | ||||||||
| ▲ | quietbritishjim 20 hours ago | parent | prev [-] | |||||||
It means the same thing in MATLAB and numpy:
Gives:
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#gene... | ||||||||
| ||||||||