# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1325191019 18000 # Node ID 2f742be03f908ea029fab3c79ab53a0dfc68e456 # Parent c299bb9f0ad043b2f3aa634916d27751ef52dc39 doc: mention how scalar broadcasting is a special case of broadcasting diff -r c299bb9f0ad0 -r 2f742be03f90 doc/interpreter/vectorize.txi --- a/doc/interpreter/vectorize.txi Thu Dec 29 15:18:10 2011 -0500 +++ b/doc/interpreter/vectorize.txi Thu Dec 29 15:36:59 2011 -0500 @@ -341,6 +341,11 @@ broadcast into matrices of size @code{[3 3]} before ordinary matrix subtraction takes place. +A special case of broadcasting that may be familiar is when all +dimensions of the array being broadcast are 1, i.e. the array is a +scalar. Thus for example, operations like @code{x - 42} and @code{max +(x, 2)} are basic examples of broadcasting. + For a higher-dimensional example, suppose @code{img} is an RGB image of size @code{[m n 3]} and we wish to multiply each color by a different scalar. The following code accomplishes this with broadcasting, @@ -409,7 +414,7 @@ For matrices @var{a} and @var{b}, consider the following: @example -c = sum (permute (a, [1, 3, 2]) .* permute (b, [3, 2, 1]), 3); +@var{c} = sum (permute (@var{a}, [1, 3, 2]) .* permute (@var{b}, [3, 2, 1]), 3); @end example @noindent @@ -417,7 +422,7 @@ across each other during elementwise multiplication in order to obtain a larger 3-D array, and this array is then summed along the third dimension. A moment of thought will prove that this operation is simply the much -faster ordinary matrix multiplication, @code{c = a*b;}. +faster ordinary matrix multiplication, @code{@var{c} = @var{a}*@var{b};}. A note on terminology: ``broadcasting'' is the term popularized by the Numpy numerical environment in the Python programming language. In other @@ -462,6 +467,10 @@ warning ("error", "Octave:broadcast"); @end example +@noindent +For broadcasting on scalars that worked in previous versions of Octave, +this warning will not be emitted. + @node Function Application @section Function Application @cindex map @@ -652,7 +661,7 @@ ## this will be two columns, the first is the difference and ## the second the mean of the two elements used for the diff. B(i,:) = [A(i+1)-A(i), (A(i+1) + A(i))/2)]; -end +endfor @end group @end example