且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

朱莉娅:外积函数

更新时间:2023-12-01 10:27:52

广播是在添加.时发生的Julia操作.当两个容器的大小相同时,这是一个元素操作.示例:如果 size(x)==size(y),则 x.*y 是逐元素的.但是,当形状不匹配时,广播才真正生效.如果其中一个是行向量并且其中一个是列向量,则输出将是 2D,其中 out[i,j] 匹配第 ij 行向量的列向量.这意味着 x .* y 是一种特殊的写外积的方法,如果一个是行,另一个是列向量.

Broadcast is the Julia operation which occurs when adding .'s around. When the two containers have the same size, it's an element-wise operation. Example: x.*y is element-wise if size(x)==size(y). However, when the shapes don't match, then broadcast really comes into effect. If one of them is a row vector and one of them is a column vector, then the output will be 2D with out[i,j] matching the ith row of the column vector with the j row vector. This means x .* y is a peculiar way to write the outer product if one a row and the other is a column vector.

一般来说,广播的作用是:

In general, what broadcast is doing is:

当维度变大时这很浪费,因此 Julia 提供了广播(),它扩展数组参数中的单例维度以匹配另一个数组中的相应维度,而不使用额外的内存

This is wasteful when dimensions get large, so Julia offers broadcast(), which expands singleton dimensions in array arguments to match the corresponding dimension in the other array without using extra memory

(来自Julia 手册)

但这可以推广到所有其他二元运算符,所以 x .- y' 就是您要寻找的.

But this generalizes to all of the other binary operators, so x .- y' is what you're looking for.