Introduction

Expression Broadcasting

broadcasting allows you to apply operations element-wise over data structures such as matrices.

Introduction

In Mech, broadcasting enables you to perform operations on data structures of different shapes and sizes without the need for explicit loops. Broadcasting rules are straightforward:

  1. If both operands are of the same shape, perform the operation element-wise.

  2. If one operand is a scalar, it is expanded to match the shape of the other operand.

If the operands have different shapes, the operation cannot occur.

For example:

A:=[
1 4
2 5
3 6
]
B:=[
10 40
20 50
30 60
]
C:=A+B

Or adding a scalar to a matrix:

A:=[
1 4
2 5
3 6
]
B:=10C:=A+B

Functions also support broadcasting:

A:=[
1 16
4 25
9 36
]
B:=math/sqrt(A)