What does operator “dot” (.) mean?

前端 未结 2 501
暖寄归人
暖寄归人 2020-11-28 12:15

Given the code :

 A = [1 2 3; 3 2 1]
 B = A.^2

The output :

B =

     1     4     9
     9     4     1

2条回答
  •  情深已故
    2020-11-28 13:00

    The dot itself is not an operator, .^ is.

    The .^ is a pointwise¹ (i.e. element-wise) power, as .* is the pointwise product.

    .^ Array power. A.^B is the matrix with elements A(i,j) to the B(i,j) power. The sizes of A and B must be the same or be compatible.

    C.f.

    • "Array vs. Matrix Operations": https://mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
    • "Pointwise": http://en.wikipedia.org/wiki/Pointwise
    • "Element-Wise Operations": http://www.glue.umd.edu/afs/glue.umd.edu/system/info/olh/Numerical/Matlab_Matrix_Manipulation_Software/Matrix_Vector_Operations/elementwise

    ¹) Hence the dot.

提交回复
热议问题