expression

Broadcast a row across a matrix

Broadcasting logically expands compatible dimensions, such as a row vector across matrix rows. This fixed-size example models addition without allocating repeated copies of the row. Real ndarray broadcasting must follow its documented axis compatibility rules; this is not an ndarray API example. Expected result (NOT RUN): [11, 22, 33] [14, 25, 36] Common mistake: Assuming arbitrary unequal axis lengths can broadcast. Static Rust example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
result[r,c] = matrix[r,c] + row[c]

Working Example

Example Snippetrust
fn main() {    let matrix = [[1, 2, 3], [4, 5, 6]];    let row = [10, 20, 30];    for values in matrix {        let result = std::array::from_fn::<_, 3, _>(|i| values[i] + row[i]);        println!("{result:?}");    }}
Rust Reference